Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,13 @@ def incompatible_argument_note(
)
if call:
self.note_call(original_caller_type, call, context, code=code)

if isinstance(callee_type, Instance) and callee_type.type.is_protocol:
call = find_member("__call__", callee_type, callee_type, is_operator=True)
if call is not None:
item = get_proper_type(call)
# should we print out all possible overloadings?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm tracing this right, for overloaded functions it will just print "overloaded function". So I'd say, yes, we should print (and whatever we do, we should probably be consistent with the other branch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated it to remove the overloaded check, should now print "overloaded function" consistent with the other note.
Thanks

if not (isinstance(item, Overloaded)):
self.note_call(callee_type, call, context, code=code)
self.maybe_note_concatenate_pos_args(original_caller_type, callee_type, context, code)

def maybe_note_concatenate_pos_args(
Expand Down
12 changes: 8 additions & 4 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -3677,7 +3677,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ...

def g(__x: str) -> None: pass
reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \
# E: Argument 1 to "f" has incompatible type "Callable[[str], None]"; expected "Call[Never]"
# E: Argument 1 to "f" has incompatible type "Callable[[str], None]"; expected "Call[Never]" \
# N: "Call[Never].__call__" has type "Callable[[NamedArg(Never, 'x')], None]"
[builtins fixtures/list.pyi]

[case testCallableInferenceAgainstCallableNamedVsPosOnly]
Expand All @@ -3693,7 +3694,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ...

def g(*, x: str) -> None: pass
reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \
# E: Argument 1 to "f" has incompatible type "Callable[[NamedArg(str, 'x')], None]"; expected "Call[Never]"
# E: Argument 1 to "f" has incompatible type "Callable[[NamedArg(str, 'x')], None]"; expected "Call[Never]" \
# N: "Call[Never].__call__" has type "Callable[[Never], None]"
[builtins fixtures/list.pyi]

[case testCallableInferenceAgainstCallablePosOnlyVsKwargs]
Expand All @@ -3709,7 +3711,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ...

def g(**x: str) -> None: pass
reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \
# E: Argument 1 to "f" has incompatible type "Callable[[KwArg(str)], None]"; expected "Call[Never]"
# E: Argument 1 to "f" has incompatible type "Callable[[KwArg(str)], None]"; expected "Call[Never]" \
# N: "Call[Never].__call__" has type "Callable[[Never], None]"
[builtins fixtures/list.pyi]

[case testCallableInferenceAgainstCallableNamedVsArgs]
Expand All @@ -3725,7 +3728,8 @@ def f(x: Call[T]) -> Tuple[T, T]: ...

def g(*args: str) -> None: pass
reveal_type(f(g)) # N: Revealed type is "Tuple[Never, Never]" \
# E: Argument 1 to "f" has incompatible type "Callable[[VarArg(str)], None]"; expected "Call[Never]"
# E: Argument 1 to "f" has incompatible type "Callable[[VarArg(str)], None]"; expected "Call[Never]" \
# N: "Call[Never].__call__" has type "Callable[[NamedArg(Never, 'x')], None]"
[builtins fixtures/list.pyi]

[case testInferenceAgainstTypeVarActualBound]
Expand Down
21 changes: 14 additions & 7 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,8 @@ def func(caller: Caller) -> None:
pass

func(call)
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int, VarArg(str)], None]"; expected "Caller"
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int, VarArg(str)], None]"; expected "Caller" \
# N: "Caller.__call__" has type "Callable[[Arg(str, 'x'), VarArg(int)], None]"
[builtins fixtures/tuple.pyi]
[out]

Expand Down Expand Up @@ -2510,7 +2511,8 @@ def func(caller: Caller) -> None:
pass

func(call)
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int], int]"; expected "Caller"
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[int], int]"; expected "Caller" \
# N: "Caller.__call__" has type "Callable[[Arg(T, 'x')], T]"
[builtins fixtures/tuple.pyi]
[out]

Expand All @@ -2530,7 +2532,8 @@ def func(caller: Caller) -> None:
pass

func(call)
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[T], Tuple[T, T]]"; expected "Caller"
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[T], Tuple[T, T]]"; expected "Caller" \
# N: "Caller.__call__" has type "Callable[[Arg(int, 'x')], int]"
[builtins fixtures/tuple.pyi]
[out]

Expand Down Expand Up @@ -2596,7 +2599,8 @@ def anon(caller: CallerAnon) -> None:


func(call)
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[str], None]"; expected "Caller"
func(bad) # E: Argument 1 to "func" has incompatible type "Callable[[str], None]"; expected "Caller" \
# N: "Caller.__call__" has type "Callable[[Arg(str, 'x')], None]"
anon(bad)
[out]

Expand All @@ -2619,7 +2623,8 @@ a: Other
b: Bad

func(a)
func(b) # E: Argument 1 to "func" has incompatible type "Bad"; expected "One"
func(b) # E: Argument 1 to "func" has incompatible type "Bad"; expected "One" \
# N: "One.__call__" has type "Callable[[Arg(str, 'x')], None]"
[out]

[case testJoinProtocolCallback]
Expand Down Expand Up @@ -3589,7 +3594,8 @@ test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P"
# N: Expected: \
# N: def __call__(x: int, y: int) -> Any \
# N: Got: \
# N: def __init__(x: int, y: str) -> C
# N: def __init__(x: int, y: str) -> C \
# N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]"

[case testProtocolClassObjectPureCallback]
from typing import Any, ClassVar, Protocol
Expand All @@ -3610,7 +3616,8 @@ test(C) # E: Argument 1 to "test" has incompatible type "Type[C]"; expected "P"
# N: Expected: \
# N: def __call__(x: int, y: int) -> Any \
# N: Got: \
# N: def __init__(x: int, y: str) -> C
# N: def __init__(x: int, y: str) -> C \
# N: "P.__call__" has type "Callable[[Arg(int, 'x'), Arg(int, 'y')], Any]"
[builtins fixtures/type.pyi]

[case testProtocolClassObjectCallableError]
Expand Down