Skip to content

feature request: explicity metaclass().__getitem__ typing #6313

Closed
@Levitanus

Description

@Levitanus

Mypy does well with metaclass __getitem__ when the class is instatiated,
but in case of indexing just the child class, it fails:

class Other:
    ...

class GenMeta(type):
    def __getitem__(cls, ref: Type[int]) -> Type[Other]:
        return Other

class Gen(metaclass=GenMeta):
    ...

a = Gen[int]  # "Gen" expects no type arguments, but 1 given
reveal_type(a)  # Revealed type is 'Any'
b = Gen[int]()
reveal_type(b)  # Revealed type is 'pyksp.simple_test.Other'


def foo(arg: Gen[int]) -> None:  # "Gen" expects no type arguments, but 1 given
    reveal_type(arg)  # Revealed type is 'pyksp.simple_test.Gen'

I think it would be very useful to check, especially in case of function annotations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions