Skip to content

Commit 44b5f41

Browse files
benkuhnddfisher
authored andcommitted
Fix is_overlapping_types for Any (#2973)
`Any` is now properly special-cased to potentially overlap with all other types. Fixes #2970.
1 parent 069392a commit 44b5f41

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

mypy/meet.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class C(A, B): ...
6969
TODO: Don't consider callables always overlapping.
7070
TODO: Don't consider type variables with values always overlapping.
7171
"""
72+
# Any overlaps with everything
73+
if isinstance(t, AnyType) or isinstance(s, AnyType):
74+
return True
75+
7276
# Since we are effectively working with the erased types, we only
7377
# need to handle occurrences of TypeVarType at the top level.
7478
if isinstance(t, TypeVarType):

test-data/unit/check-optional.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ else:
7777
reveal_type(x) # E: Revealed type is 'builtins.int'
7878
[builtins fixtures/bool.pyi]
7979

80+
[case testAnyCanBeNone]
81+
from typing import Optional, Any
82+
x = None # type: Any
83+
if x is None:
84+
reveal_type(x) # E: Revealed type is 'builtins.None'
85+
else:
86+
reveal_type(x) # E: Revealed type is 'Any'
87+
[builtins fixtures/bool.pyi]
88+
8089
[case testOrCases]
8190
from typing import Optional
8291
x = None # type: Optional[str]

0 commit comments

Comments
 (0)