Created
March 16, 2025 18:23
-
-
Save mypy-play/7887dda55773a9af7eaf3028f5e7a9f4 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
# remove the typing hints and mypy fails | |
from typing import Callable, Union | |
def fun1(x: int) -> Callable[[int], int]: | |
return lambda y: x + y | |
x = fun1(1) | |
reveal_type(x) | |
def funf(f: Callable[[int], int]) -> int: | |
return f(1) | |
y = funf(lambda x: x) | |
reveal_type(y) | |
def funz(x): | |
return x | |
z: int = funz(3) | |
reveal_type(z) | |
def funk(x): | |
return lambda y: y | |
# a = funk(1) | |
a: Callable[..., int] = funk(1)(1) | |
reveal_type(a) | |
# (ππ . π 1) : ((πΌ β πΌ ) & (πΉ β πΉ )) β πΌ | |
def funsubs(f) -> Union[Callable[[int], int], Callable[[float], float]]: | |
return f(1) | |
b = funsubs(lambda x: x) | |
# reveals union or float | |
reveal_type(b(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mypy contexts