Skip to content

Hint at argument names when formatting callables with compatible return types in error messages #18495

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

Merged
merged 4 commits into from
Jan 22, 2025

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jan 20, 2025

Fixes #18493.

Improves message in #12013 and #4530, but probably still doesn't make it clear enough.

Use higher verbosity for type formatting in error message if callables' return types are compatible and supertype has some named arguments, as that is a popular source of confusion.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

werkzeug (https://github.com/pallets/werkzeug)
- tests/live_apps/run.py:35: error: Incompatible types in assignment (expression has type "Callable[[WSGIRequestHandler], Any]", variable has type "Callable[[WSGIRequestHandler], str]")  [assignment]
+ tests/live_apps/run.py:35: error: Incompatible types in assignment (expression has type "Callable[[Arg(WSGIRequestHandler, '_')], Any]", variable has type "Callable[[Arg(WSGIRequestHandler, 'self')], str]")  [assignment]

@sterliakov sterliakov marked this pull request as ready for review January 21, 2025 00:14
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.

Thanks!

@hauntsaninja hauntsaninja merged commit 48f9fc5 into python:master Jan 22, 2025
18 checks passed
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
…rn types in error messages (python#18495)

Fixes python#18493.

Improves message in python#12013 and python#4530, but probably still doesn't make it
clear enough.

Use higher verbosity for type formatting in error message if callables'
return types are compatible and supertype has some named arguments, as
that is a popular source of confusion.
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.

Misleading error message when using ParamSpec with higher-order decorators and async functions
2 participants