adorn.unit.simple module
Container of types with a flat class hierarchy.
- class adorn.unit.simple.Simple
Bases:
adorn.unit.unit.UnitUnitfor types with a flat class hierarchy- _registry
contains mapping from
strtoType- Type
ClassVar[DefaultDict[type, _SubclassRegistry]]
- from_obj(target_cls, orchestrator, obj)
Convert obj to an instance of the type
target_cls- Parameters
target_cls (Type) – the target Type, the given
objwill be converted into an instance oforchestrator (Orchestrator) – container of all types, typically used to recurse down nested types
obj (Any) – an instance, that will be converted to an instance of
target_cls
- Returns
an instance of
target_clsthat was derived fromobj- Return type
Any
- Raises
UnRepresentedTypeError –
objdid not map to any of the types contained in the_registry
- classmethod register(name)
Decorator that adds a type to the
_registry- Parameters
name (str) – The
strthat will map to the given type- Returns
- funcion that adds the decorated type
to the
_registrywith thenamebeing the key and the decorated class being the value
- Return type
Callable[[Type[_T]], Type[_T]]
- relevant_types(key, orchestrator)
Iterable containing the types that map to the given
key- Parameters
key (Any) – the object to check if it maps to any types in the
_registryorchestrator (Orchestrator) – container of all types, typically used to recurse down nested types
- Returns
collection of types in the
registrythat map tokey- Return type
Iterable[Type]
- type_check(target_cls, orchestrator, obj)
Ensure obj can be converted to the type
target_cls- Exceptions:
UnRepresentedTypeError:objdid not map to any of the types contained in the_registry
- Parameters
target_cls (Type) – the target Type, the given
objwill be checked againstorchestrator (Orchestrator) – container of all types, typically used to recurse down nested types
obj (Any) – an instance, that will be checked to see if it can be converted to an instance of
target_cls
- Returns
- if
TypeCheckErrorthen there was an issue which would prevent converting
objto an instance oftarget_cls, otherwiseNone
- if
- Return type
Optional[TypeCheckError]