Sujet : Re: Any way to "subclass" typing.Annotated?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 29. Jan 2025, 14:48:00
Autres entêtes
Organisation : Stefan Ram
Message-ID : <Any-20250129144747@ram.dialup.fu-berlin.de>
References : 1 2
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
Option 2: Custom Wrapper Class
To compile, this should read:
Python
from typing import Annotated, TypeVar, Generic, Any
# Your trusty "abstract" flag, chillin' like it's at Venice Beach
abstract = object()
# Type variable, as constant as the NorCal fog
T = TypeVar("T")
class AbstractClassVariable(Generic[T]):
def __class_getitem__(cls, item: T) -> Any:
return Annotated[item, abstract]