Skip to content

Instantly share code, notes, and snippets.

@agronholm
Created September 30, 2020 13:54
Show Gist options
  • Save agronholm/f73bd2806a5f4cd8bd7c04a59c08ea60 to your computer and use it in GitHub Desktop.
Save agronholm/f73bd2806a5f4cd8bd7c04a59c08ea60 to your computer and use it in GitHub Desktop.
test.py:13: note: Revealed type is 'Any'
test.py:13: note: 'reveal_type' always outputs 'Any' in unchecked functions
test.py:15: note: Revealed type is 'Any'
test.py:15: note: 'reveal_type' always outputs 'Any' in unchecked functions
test.py:17: note: Revealed type is 'Any'
test.py:17: note: 'reveal_type' always outputs 'Any' in unchecked functions
test.py:20: error: No overload variant of "foo" matches argument type "float"
test.py:20: note: Possible overload variants:
test.py:20: note: def foo(bar: Union[bytes, str]) -> str
test.py:20: note: def foo(bar: int) -> int
Found 1 error in 1 file (checked 1 source file)
from typing import Union, overload
@overload
def foo(bar: Union[bytes, str]) -> str: ...
@overload
def foo(bar: int) -> int: ...
def foo(bar):
reveal_type(a) # Union[builtins.bytes, builtins.str, builtins.int]
if isinstance(bar, int):
reveal_type(bar) # builtins.str
return str(bar) # mypy -> expected: error, actual: no error
reveal_type(bar) # Union[builtins.bytes, builtins.str]
return bar # mypy -> expected: error, actual: error
foo(4.33)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment