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
11 changes: 8 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,9 +1775,14 @@ def overload_arg_similarity(actual: Type, formal: Type) -> int:
(isinstance(actual, Instance) and actual.type.fallback_to_any)):
# These could match anything at runtime.
return 2
if not experiments.STRICT_OPTIONAL and isinstance(actual, NoneTyp):
# NoneTyp matches anything if we're not doing strict Optional checking
return 2
if isinstance(actual, NoneTyp):
if not experiments.STRICT_OPTIONAL:
# NoneTyp matches anything if we're not doing strict Optional checking
return 2
else:
# NoneType is a subtype of object
if isinstance(formal, Instance) and formal.type.fullname() == "builtins.object":
return 2
if isinstance(actual, UnionType):
return max(overload_arg_similarity(item, formal)
for item in actual.items)
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,14 @@ def f(b: T) -> T:
a = None
b = "foo"
reveal_type(a and b) # E: Revealed type is 'builtins.None'

[case testNoneMatchesObjectInOverload]
import a
a.f(None)

[file a.pyi]
from typing import overload
@overload
def f() -> None: ...
@overload
def f(o: object) -> None: ...