Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created December 28, 2025 23:05
Show Gist options
  • Select an option

  • Save mypy-play/255cd3ec7758baa1b33009dc2be5de70 to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/255cd3ec7758baa1b33009dc2be5de70 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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