tierriminator
tierriminator

Reputation: 649

Type aliasing Python's `typing.Annotated` type

Assuming, I have some generic type Foo[T]. How can I create an alias AFoo[T, x] = Annotated[Foo[T], x] or something similar, which works with pyright, but also let's me extract the metadata and type hint x and T?

What I've tried so far:

T = TypeVar("T")
AFoo = Annotated[Foo[T], Any]
T = TypeVar("T")
class AFoo(Generic[T]):
    def __class_getitem__(cls, params: tuple[type[T], Any]):
        t, x = params
        return Annotated[Foo[t], x]

Both approaches seem to fail because pyright seems to expect that AFoo[str, "bar"] is equivalent to Foo[str, "bar"].

Upvotes: 1

Views: 78

Answers (0)

Related Questions