Skip to content

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

Merged
hauntsaninja merged 4 commits into
python:masterfrom
sterliakov:bugfix/st-callable-formatting
Jan 22, 2025
Merged

Hint at argument names when formatting callables with compatible return types in error messages#18495
hauntsaninja merged 4 commits into
python:masterfrom
sterliakov:bugfix/st-callable-formatting

Conversation

@sterliakov

@sterliakov sterliakov commented Jan 20, 2025

Copy link
Copy Markdown
Collaborator

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
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

@hauntsaninja hauntsaninja left a comment

Copy link
Copy Markdown
Collaborator

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
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