Show the signature of __call__ for arguments with incompatible types …#18214
Conversation
This comment has been minimized.
This comment has been minimized.
mypy/messages.py
Outdated
| 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? |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
I updated it to remove the overloaded check, should now print "overloaded function" consistent with the other note.
Thanks
|
Diff from mypy_primer, showing the effect of this PR on open source code: sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/application.py:1097:38: note: "RoleFunction.__call__" has type "Callable[[str, str, str, int, Inliner, DefaultArg(dict[str, Any] | None, 'options'), DefaultArg(Sequence[str], 'content')], tuple[list[Node], list[system_message]]]"
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/ext/commands/commands.py:916: note: "Check[bool | Coroutine[Any, Any, bool]].__call__" has type overloaded function
|
hauntsaninja
left a comment
There was a problem hiding this comment.
Thank you!
If you want a related follow-up, it could be nice to render Callable[[Arg(int, 'x'), Arg(int, 'y')], Any] as (x: int, y: int) -> Any. The argument constructors from mypy_extensions never really went anywhere: https://github.com/python/mypy_extensions/blob/master/mypy_extensions.py#L117-L149 (we now use callback Protocols)
fixes issue #17840
Check if callee_type.is_protocol if so calls find_member like before on the callee_type and then calls self.note_call() to report the note.
Checks if isinstance(Overloaded) and does nothing for now since it returns
which in my opinion is unhelpful.
Updated test cases to reflect all of the changes.