Created
December 7, 2025 10:11
-
-
Save mypy-play/1cbeed44a7e559bac3a2a1e93f5a4a7f 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, 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