Created
December 28, 2025 23:05
-
-
Save mypy-play/255cd3ec7758baa1b33009dc2be5de70 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import TypeVar, Generator | |
| from types import coroutine | |
| T = TypeVar("T", str, bytes) | |
| async def process(data: T) -> T: | |
| return data | |
| @coroutine | |
| def process2(data: T) -> Generator[T, None, T]: | |
| yield data | |
| return data | |
| async def _typecheck() -> None: | |
| reveal_type(process) | |
| reveal_type(await process("hello")) | |
| reveal_type(await process(b"bytes")) | |
| # reveal_type(await process(1)) # correctly rejected | |
| reveal_type(process2) | |
| reveal_type(process2("hello")) | |
| reveal_type(process2(b"bytes")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment