Created
July 12, 2021 18:04
-
-
Save ramalho/9a3742c563e300da0efd2b06803872e5 to your computer and use it in GitHub Desktop.
This file contains 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, TYPE_CHECKING | |
BT = TypeVar('BT', bound=float) | |
def triple2(a: BT) -> BT: | |
return a * 3 | |
res2 = triple2(2) | |
if TYPE_CHECKING: | |
reveal_type(res2) | |
""" | |
Mypy output: | |
$ mypy typevar_bounded.py | |
typevar_bounded.py:6: error: Incompatible return value type (got "float", expected "BT") | |
typevar_bounded.py:11: note: Revealed type is "builtins.int*" | |
Found 1 error in 1 file (checked 1 source file) | |
$ mypy --version | |
mypy 0.910 | |
""" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment