Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created June 10, 2026 14:08
Show Gist options
  • Select an option

  • Save mypy-play/9cbb94b203fd103f1c9ef2b812121e3a to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/9cbb94b203fd103f1c9ef2b812121e3a to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import (
Generic,
Literal,
TypeAlias,
overload,
)
from typing_extensions import (
TypeVar,
)
Storage: TypeAlias = Literal["python", "pyarrow"]
StorageT = TypeVar("StorageT", bound=Storage)
_StorageT = TypeVar("_StorageT", bound=Storage | None, default=None)
class _StringDtypeStorageDescriptor:
@overload
def __get__(
self, instance: StringDtype[None], owner: type[StringDtype[None]]
) -> Storage: ...
@overload
def __get__(
self, instance: StringDtype[StorageT], owner: type[StringDtype[StorageT]]
) -> StorageT: ...
class StringDtype(Generic[_StorageT]):
storage = _StringDtypeStorageDescriptor()
reveal_type(StringDtype[Literal["python"]]().storage) # mypy, pyright, ty: Literal["python"], pyrefly: error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment