mypy
mypy copied to clipboard
Mypy thinks that `class` statement always produces some class
from typing import Any
s: Any = slice(1, 2, 3)
class X(s): ...
print(X) # slice('X', (slice(1, 2, 3),), {'__module__': '__main__', '__qualname__': 'X'})
x = X() # TypeError: 'slice' object is not callable
reveal_type(x) # test.X
reveal_type(X) # def (*_args: Any, **_kwds: Any) -> test.X
At runtime X is not a class, it is instance of slice, but mypy thinks that class statement always produces some class.
Expected Behavior
- no errors
- revealed types
AnyandAny
Actual Behavior
- no errors
- revealed type
Xanddef (...) -> X, what is wrong
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes) - Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10.6
- Operating system and version: Win10
The same is true for:
- Classs decorators that return something else
- Custom metaclasses that return something else
- Probably other magic :)
But, yes, this is a limitation we have for now.