Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created December 7, 2025 10:11
Show Gist options
  • Select an option

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

Select an option

Save mypy-play/1cbeed44a7e559bac3a2a1e93f5a4a7f to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import TypeVar, Callable, reveal_type
IntOrStr = TypeVar("IntOrStr", str, int)
def rint() -> int:
return 1
def rstr() -> str:
return "A"
def f(func: Callable[[], IntOrStr])->IntOrStr:
return func()
def g[T: int|str](func: Callable[[], T])->T:
return func()
reveal_type(f(rint))
reveal_type(f(rstr))
reveal_type(g(rint))
reveal_type(g(rstr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment