python / python/mypy

`reveal_type()` cannot get `*Ts` type of the instance of a generic class

Open
#20,388 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug pending
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

*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()) # ()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example in test.py with mypy --strict and compare reveal_type() for T with the variadic *Ts case. Trace the generic-class inference path responsible for instance types, then add coverage showing the default tuple type is revealed as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.