jgdv.mixins.annotate.aliaser
Type Aliases
Classes
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