mypy
mypy copied to clipboard
`reveal_type()` cannot get `*Ts` type of the instance of a generic class
*Memo:
-
mypy --strict test.py - mypy 1.19.0
- Python 3.14.0
- Windows 11
reveal_type() can get T type of the instance of a generic class as shown below:
class MyCls[T = int]:
def __init__(self, x: T | None = None) -> None: ...
reveal_type(MyCls()) # builtins.int
But reveal_type() cannot get *Ts type of the instance of a generic class as shown below:
class MyCls[*Ts = *tuple[int, ...]]:
def __init__(self, *args: *Ts) -> None: ...
reveal_type(MyCls()) # ()
Could you explain the problem? () aka empty tuple is the only correct parameterization here, what output do you expect? Zero args form an empty tuple, and MyCls[()] is what mypy prints for your example.