Skip to content

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

@jonathandung

Description

@jonathandung

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions