Skip to content

Instantly share code, notes, and snippets.

@ramalho
Created July 12, 2021 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramalho/9a3742c563e300da0efd2b06803872e5 to your computer and use it in GitHub Desktop.
Save ramalho/9a3742c563e300da0efd2b06803872e5 to your computer and use it in GitHub Desktop.
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