Skip to content

mypy does not handle __class_getitem__ #11501

@jayanthkoushik

Description

@jayanthkoushik

PEP 560 defines __class_getitem__ as a way to enable indexing a class (to define custom generic types for instance), but mypy does not seem to recognize this.

To Reproduce

$ cat test.py
class A:
    def __class_getitem__(cls, item):
        return cls

x = A[int]

$ mypy test.py

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

test.py:6: error: "A" expects no type arguments, but 1 given
Found 2 errors in 1 file (checked 1 source file)

Environment

  • mypy 0.910
  • Python 3.9.7
  • Darwin arm64

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions