Generic argument is not being identified
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
The code in this mypy playground raises the following error.
Name "T" is not defined [name-defined]
However, as seen in this pyright playground there is no error, which leads me to believe that the snippet is well defined.
This one is probably related but the revealed types do not seem to match as well (the ? in the type name seems to be rather strange).
mypy
"__main__.Repo[T?, U`-2]"
pyright
"Repo[T@some, U@some]"
To Reproduce (this is the same code as in the mypy playground)
from typing import cast, reveal_type
from collections.abc import Callable
class Repo[T, U]: ...
def some[T, U, **P](func: Callable[P, U]) -> Callable[P, U]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> U:
reveal_type(cast(Repo[T, U], args[0]))
return func(*args, **kwargs)
return wrapper
Expected Behavior
No errors from mypy, similar behavior to pyright.
Actual Behavior
I am not sure if mypy is misdiagnosing this, if you feel this is intended behavior I can try raising an issue with pyright.
Your Environment
- Mypy version used: 1.15.0 (playground)
- Pyright version used: 1.1.399 (playground)
- Mypy command-line flags: default settings in mypy playground (if I am not mistaken, there are no extra flags)
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.13 (for both playgrounds)
Thank You
Edit: Simplified the example a bit by removing the bounds and awaitables.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked mypy playground and the minimal reproduction under “To Reproduce,” comparing its result with the linked pyright playground. Trace how the generic parameters T and U are resolved inside wrapper and in cast(Repo[T, U], args[0]); done means mypy no longer reports T as undefined and its revealed type is consistent with the expected generic form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100