Skip to content

Commit 6c986cc

Browse files
committed
Use a simpler heuristic: just check if callables are subtypes if we ignore argnames
1 parent 74f5a57 commit 6c986cc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

mypy/messages.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,13 +2872,8 @@ def format_single(arg: Type) -> str:
28722872
if (
28732873
isinstance(left, CallableType)
28742874
and isinstance(right, CallableType)
2875-
and is_subtype(left.ret_type, right.ret_type)
28762875
and any(right.arg_names)
2877-
and len(right.arg_types) == len(left.arg_types)
2878-
and all(
2879-
format_single(aleft) == format_single(aright)
2880-
for aleft, aright in zip(left.arg_types, right.arg_types)
2881-
)
2876+
and is_subtype(left, right, ignore_pos_arg_names=True)
28822877
):
28832878
min_verbosity = 1
28842879

test-data/unit/check-functions.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,3 +3510,13 @@ class Child(Parent):
35103510
method_without: Callable[["Child"], "Child"]
35113511
method_with: Callable[["Child", str], "Child"] # E: Incompatible types in assignment (expression has type "Callable[[str], Child]", base class "Parent" defined the type as "Callable[[Arg(str, 'param')], Parent]")
35123512
[builtins fixtures/tuple.pyi]
3513+
3514+
[case testDistinctFormattingUnion]
3515+
from typing import Callable, Union
3516+
from mypy_extensions import Arg
3517+
3518+
def f(x: Callable[[Arg(int, 'x')], None]) -> None: pass
3519+
3520+
y: Callable[[Union[int, str]], None]
3521+
f(y) # E: Argument 1 to "f" has incompatible type "Callable[[Union[int, str]], None]"; expected "Callable[[Arg(int, 'x')], None]"
3522+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)