-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Show name of type variable in "Cannot infer type argument" message #19290
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 name of type variable in "Cannot infer type argument" message #19290
Conversation
primer shard 0 died due to hitting the 60 minute timeout :( |
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.
LG! Only a minor optional nit:
This comment has been minimized.
This comment has been minimized.
I'm a little confused how a new test case in master is leaking into this PR's CI: https://github.com/python/mypy/actions/runs/15734614442/job/44343883908?pr=19290#step:9:210 The failing case was added in #19279. That commit isn't in this branch's history and the failing case does not exist locally. Trivial to fix, but still weird. |
mypy/messages.py
Outdated
self.fail(f"Cannot infer type argument {n} of {callee_name}", context) | ||
if callee_name is not None: | ||
self.fail( | ||
f"Cannot infer type argument to type parameter {format_type(tv, self.options)} of {callee_name}", |
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.
"type argument to type parameter" feels unnecessarily verbose. I think this is clear enough:
f"Cannot infer type argument to type parameter {format_type(tv, self.options)} of {callee_name}", | |
f"Cannot infer type argument {format_type(tv, self.options)} of {callee_name}", |
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.
Yeah, I agree with this being verbose. Cannot infer type argument "T"
originally sounded off to me since T
isn't a type argument, it's the type parameter whose argument mypy is trying to infer.
Maybe Cannot infer value of type parameter "T" of "f"
? I'm also fine with the suggested wording if that's your preference.
|
TIL, thank you! |
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/task_engine.py:648: error: Cannot infer type argument 2 of "update_for_task" of "ResultStore" [misc]
+ src/prefect/task_engine.py:648: error: Cannot infer value of type parameter "R" of "update_for_task" of "ResultStore" [misc]
- src/prefect/task_engine.py:1233: error: Cannot infer type argument 2 of "update_for_task" of "ResultStore" [misc]
+ src/prefect/task_engine.py:1233: error: Cannot infer value of type parameter "R" of "update_for_task" of "ResultStore" [misc]
werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/datastructures/structures.py:711: error: Cannot infer type argument 2 of "setdefault" of "MutableMapping" [misc]
+ src/werkzeug/datastructures/structures.py:711: error: Cannot infer value of type parameter "_VT" of "setdefault" of "MutableMapping" [misc]
|
Fixes #19289
The type argument index currently shown can be wrong if other type arguments were substituted during an earlier pass.
Given:
Before:
After: