Open
Description
Bug Report
When a class:
- is defined inside a function, and
- uses a metaclass
then it mypy will inconsistently give an Invalid metaclass
error based on whether the metaclass is specified via an alias name, or the original name from when the class is defined. This behaviour occurs regardless of whether the metaclass is defined inside or outside of the function. I would have expected no error.
To Reproduce
class M(type):
pass
def f() -> None:
_M = M
class C(metaclass=_M): # Error
pass
class D(metaclass=M): # OK
pass
Actual Behavior
main.py:8: error: Invalid metaclass "_M" [misc]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.1.1
- Python version used: 3.11