adorn.unit.simple module
Container of types with a flat class hierarchy.
- class adorn.unit.simple.Simple
Bases:
adorn.unit.unit.Unit
Unit
for types with a flat class hierarchy- _registry
contains mapping from
str
toType
- 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
obj
will 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_cls
that was derived fromobj
- Return type
Any
- Raises
UnRepresentedTypeError –
obj
did 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
str
that will map to the given type- Returns
- funcion that adds the decorated type
to the
_registry
with thename
being 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
_registry
orchestrator (Orchestrator) – container of all types, typically used to recurse down nested types
- Returns
collection of types in the
registry
that map tokey
- Return type
Iterable[Type]
- type_check(target_cls, orchestrator, obj)
Ensure obj can be converted to the type
target_cls
- Exceptions:
UnRepresentedTypeError
:obj
did not map to any of the types contained in the_registry
- Parameters
target_cls (Type) – the target Type, the given
obj
will 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
TypeCheckError
then there was an issue which would prevent converting
obj
to an instance oftarget_cls
, otherwiseNone
- if
- Return type
Optional[TypeCheckError]