Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class C(A, B): ...
TODO: Don't consider callables always overlapping.
TODO: Don't consider type variables with values always overlapping.
"""
# Any overlaps with everything
if isinstance(t, AnyType) or isinstance(s, AnyType):
return True

# Since we are effectively working with the erased types, we only
# need to handle occurrences of TypeVarType at the top level.
if isinstance(t, TypeVarType):
Expand Down
9 changes: 9 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ else:
reveal_type(x) # E: Revealed type is 'builtins.int'
[builtins fixtures/bool.pyi]

[case testAnyCanBeNone]
from typing import Optional, Any
x = None # type: Any
if x is None:
reveal_type(x) # E: Revealed type is 'builtins.None'
else:
reveal_type(x) # E: Revealed type is 'Any'
[builtins fixtures/bool.pyi]

[case testOrCases]
from typing import Optional
x = None # type: Optional[str]
Expand Down