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 to Type

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 of

  • orchestrator (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 from obj

Return type

Any

Raises

UnRepresentedTypeErrorobj 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 the name 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 to key

Return type

Iterable[Type]

type_check(target_cls, orchestrator, obj)

Ensure obj can be converted to the type target_cls

Exceptions:
Parameters
  • target_cls (Type) – the target Type, the given obj will be checked against

  • orchestrator (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 of target_cls, otherwise None

Return type

Optional[TypeCheckError]