Bug Report
In a class whose body is nested in another, mypy doesn't recognize the type parameters of the outer class as bound in the inner.
To Reproduce
# test_mypy.py
class Foo[T]:
class Bar[R]:
def foobar(self, t: T, r: R, /) -> None: ...
print(T, R)
Output of program
Note that there is no NameError being thrown. The names T and R are indeed both bound in the scope of the definition of R.
Actual Behavior
test_mypy.py:3: error: Name "T" is not defined [name-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
- Command used: mypy test_mypy.py
- Mypy configuration options from
mypy.ini (and other config files): None relevant
- Python version used: 3.12, 3.13, 3.14
Bug Report
In a class whose body is nested in another, mypy doesn't recognize the type parameters of the outer class as bound in the inner.
To Reproduce
Output of program
Note that there is no
NameErrorbeing thrown. The namesTandRare indeed both bound in the scope of the definition ofR.Actual Behavior
Your Environment
mypy.ini(and other config files): None relevant