python / python/mypy

stubtest false positive when `__class_getitem__` is implemented in class body and corresponding body in stub is generic

Open
#21,253 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

To Reproduce

In _mypy/_1.py:

class spam:
    def __class_getitem__(cls, _, /): return cls

In _mypy/_1.pyi:

class spam[T]: ...

Expected Behavior

Stubtest should not report any errors. The class is implemented to be generic since a __class_getitem__ method is provided, and type-checked to be generic from the type parameter syntax.

Actual Behavior

error: _mypy._1.spam.__class_getitem__ is not present in stub
Stub: in file /_mypy/_1.pyi
MISSING
Runtime: in file /_mypy/_1.py:2
def (_, /)

Your Environment

  • Mypy version used: 1.20.0
  • Command used: python -m mypy.stubtest _mypy
  • Python version used: 3.14

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 with the _mypy/_1.py and _mypy/_1.pyi reproduction and run python -m mypy.stubtest _mypy. Trace how stubtest compares class_getitem with a generic class declared using type parameter syntax; done means the command reports no missing-member error for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.