-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show the signature of __call__ for arguments with incompatible types … #18214
Show the signature of __call__ for arguments with incompatible types … #18214
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! One small note re: your question
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.
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)
There was a problem hiding this comment.
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
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.