Skip to content

Fix is_overlapping_types(NoneTyp, AnyType) for strict Optional checking #2973

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 15, 2017
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