adorn.unit.unit module

Collection of similar types or values.

class adorn.unit.unit.Unit

Bases: object

A collection of types or values, that usually have some shared characteristic(s).

contains(obj, orchestrator)

Check if obj has a corresponding type in Unit

Parameters
  • obj (Any) – the Type that may be a subclass of the given Unit

  • orchestrator (Orchestrator) – container of all types, typically used to recurse down nested types

Raises

NotImplementedError – This method must be overriden by a subclass

Return type

bool

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

  • 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

Raises

NotImplementedError – This method must be overriden by a subclass

Return type

Any

get(key, orchestrator)

Return the relevant Type for the key

Parameters
  • key (Any) – the Type that may be a subclass of the Unit

  • orchestrator (Orchestrator) – container of all types, typically used to recurse down nested types

Raises

NotImplementedError – This method must be overriden by a subclass

Return type

Optional[type]

hashable: bool = False

If True then instances of the given type are hashable

classmethod register(name)

Decorator that maps a string to the type

Parameters

name (str) – a string that will be the key for a Type

Raises

NotImplementedError – This method must be overriden by a subclass

Return type

Callable[[Type[adorn.unit.unit._T]], Type[adorn.unit.unit._T]]

type_check(target_cls, orchestrator, obj)

Ensure obj can be converted to the type target_cls

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

Raises

NotImplementedError – This method must be overriden by a subclass

Return type

Optional[adorn.exception.type_check_error.TypeCheckError]