KEMBAR78
Hint at argument names when formatting callables with compatible return types in error messages by sterliakov · Pull Request #18495 · python/mypy · GitHub
Skip to content

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.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
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