Skip to content

Commit 38b47b0

Browse files
committed
Another fix to overload resolution
1 parent 748c6f4 commit 38b47b0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/checkexpr.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,9 @@ def visit_erased_type(self, t: ErasedType) -> bool:
13991399

14001400
def is_compatible_overload_arg(actual: Type, formal: Type) -> bool:
14011401
if (isinstance(actual, NoneTyp) or isinstance(actual, AnyType) or
1402-
isinstance(formal, AnyType) or isinstance(formal, TypeVar)):
1402+
isinstance(formal, AnyType) or isinstance(formal, TypeVar) or
1403+
isinstance(formal, Callable)):
1404+
# These could match anything at runtime.
14031405
return True
14041406
if isinstance(actual, UnionType):
14051407
return any(is_compatible_overload_arg(item, formal)
@@ -1418,4 +1420,5 @@ def is_compatible_overload_arg(actual: Type, formal: Type) -> bool:
14181420
return formal.type in actual.type.mro
14191421
else:
14201422
return False
1423+
# Fall back to a conservative equality check for the remaining kinds of type.
14211424
return is_same_type(erasetype.erase_type(actual), erasetype.erase_type(formal))

mypy/test/data/pythoneval.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,3 +919,11 @@ map(f, ['x'])
919919
map(f, [1])
920920
[out]
921921
_program.py, line 4: Argument 1 to "map" has incompatible type Function[["str"] -> "str"]; expected Function[["int"] -> "str"]
922+
923+
[case testMapStr]
924+
import typing
925+
x = range(3)
926+
a = list(map(str, x))
927+
a + 1
928+
[out]
929+
_program.py, line 4: Unsupported operand types for + (List[str] and "int")

0 commit comments

Comments
 (0)