Skip to content
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

Merged

Conversation

MechanicalConstruct
Copy link
Contributor

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

note: "C.__call__" has type overloaded function

which in my opinion is unhelpful.
Updated test cases to reflect all of the changes.

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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?
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

Copy link
Contributor

github-actions bot commented Dec 2, 2024

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

Copy link
Collaborator

@hauntsaninja hauntsaninja left a 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)

@hauntsaninja hauntsaninja merged commit 222b104 into python:master Dec 2, 2024
19 checks passed
@MechanicalConstruct MechanicalConstruct deleted the function-argument-notes branch December 3, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants