Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created March 9, 2025 20:40
Show Gist options
  • Save mypy-play/dfe06f06e69d157317a667311aa75952 to your computer and use it in GitHub Desktop.
Save mypy-play/dfe06f06e69d157317a667311aa75952 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import TypeVar, Generic, ClassVar, Self
T = TypeVar("T", bound="BaseModel")
class BaseModel:
_meta: "ClassVar[Meta[Self]]"
class Meta(Generic[T]):
def __init__(self, model: type[T]) -> None:
self.model = model
@classmethod
def __init_subclass__(cls) -> None:
cls._meta = cls.Meta(cls)
reveal_type(BaseModel._meta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment