jgdv.mixins.annotate.aliaser

Type Aliases

AliasAnnotation

Classes

SubAlias_m

A Mixin to manage generics that resolve to specific registered subclasses.

Module Contents

jgdv.mixins.annotate.aliaser.AliasAnnotation: TypeAlias = type | str | enum.Enum | Literal[False] | Literal[True] | tuple[AliasAnnotation, ...]
class jgdv.mixins.annotate.aliaser.SubAlias_m[source]

A Mixin to manage generics that resolve to specific registered subclasses.

On class declaration, recognizes kwargs: - fresh_registry:bool : use a separate registry for this class and subclasses - accumulate:bool : annotations accumulate from their parent class - strict:bool : error if a subclass tries to overwrite a registration - default:bool : set this subclass as the default if no marks are specified when creating an instance - annotation:Maybe[str|type|enum|tuple[…]] : the key to use for this subclass, if class_getitem hasn’t been used - no_register:bool : create the class, but don’t register it

cls[val] -> GenericAlias(cls, val)

then:

class RealSub(cls[val]) … after which: cls[val] is RealSub

Annotation Keys are stored in cls.__annotation__, under the cls._annotate_to key name.

classmethod _build_annotation(annotate) <Unknown>[source]

single point of truth for determining annotations from a cls and provided annotation

Parameters:

annotate (jgdv.Maybe[AliasAnnotation])

Return type:

AliasAnnotation

classmethod _clear_registry() <Unknown>[source]
Return type:

None

classmethod _retrieve_subtype(key) <Unknown>[source]
Parameters:

key (SubAlias_m._retrieve_subtype.K)

Return type:

type | types.GenericAlias

classmethod cls_annotation() <Unknown>[source]
Return type:

tuple

_accumulator: ClassVar[bool] = False
_annotate_to: ClassVar[str] = '__jgdv_typevar__'
_default_k: ClassVar[str] = '__default__'
_registry: ClassVar[dict[AliasAnnotation, type]]
_strict: ClassVar[bool] = False