Skip to content

Pyright does not respect __class_getitem__ annotations. #11561

Description

Describe the bug

Pyright does not seem to respect type-annotations defined by custom __class_getitem__ implementations.

It assumes the getitem will return the associated class type regardless of the annotations present.

Code or Screenshots

from typing import Annotated, TypeVar, cast, reveal_type

T = TypeVar('T')

class Foo:
    @classmethod
    def __class_getitem__(cls, type: T) -> T:
        return cast(T, Annotated[type, cls()])

foo = Foo[str]
reveal_type(foo) # Type of "foo" is "type[Foo]"

In the example above the type should report as str.

VS Code extension or command-line

This issue exists both in LSP and with the latest version of the pyright command-line v1.1.411

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions