adorn.unit.constructor_value module

Different ways to handle instances of Constructor

class adorn.unit.constructor_value.BaseConstructorValue

Bases: adorn.unit.constructor_value.ConstructorValue

Vanilla way of type checking and instantiating Constructor instances

class adorn.unit.constructor_value.ConstructorValue

Bases: adorn.unit.simple.Simple

Unit that contains all the ways to handle Constructor instances.

static check_parameter_order(target_cls)

Ensure parameter_order specifies all the parameters.

Parameters

target_cls (Constructor) – subclass specifies a parameter_order

Returns

if parameter_order

is complete then None, otherwise ParameterOrderError, which specifies the additional and/or missing parameters in parameter_order

Return type

Optional[ParameterOrderError]

contains(obj, orchestrator)

Check if the obj is an instance of Constructor

Parameters
Returns

if True, obj is an instance of

Constructor

Return type

bool

static dict_type_check(target_cls, orchestrator, obj)

Type check all the arguments in obj

Parameters
  • target_cls (Constructor) – instance of Constructor, which specifies the parameters for the constructor

  • orchestrator (Orchestrator) – container of all types, used to check the arguments

  • obj (Any) – an instance, containing the arguments for subclass

Returns

if all the args type check then None,

otherwise KeyValueError, which specifies the args that failed and why

Return type

Optional[KeyValueError]

from_obj(target_cls, orchestrator, obj)

Instantiate the arguments and an instance of subclass

Parameters
  • target_cls (Constructor) – instance of Constructor

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

  • obj (Any) – an instance, containing the arguments for subclass

Returns

An instance of subclass

Return type

Any

get(key, orchestrator)

Get the relevant class to handle the given Constructor instance.

The constructor_type attached to the subclass is used to determine which subclass of ConstructorValue to use. If constructor_type is None then BaseConstructorValue will be returned

Parameters
  • key (Any) – potentially an instance of Constructor`

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

Returns

if key is an instance of

Constructor then a subclass of ConstructorValue will be returned, otherwise None

Return type

Optional[ConstructorValue]

static get_kv(main, alter_value, sub, missing, check=<function ConstructorValue.<lambda>>)

Generate the difference in keys between main and sub.

Parameters
  • main (Dict[str, Any]) – a dict, whose keys are considered necessary

  • alter_value (Callable[..., type]) – an alteration performed to a value of main before it is added to the returned result

  • sub (Dict[str, Any]) – a dict which is checked that it contains the keys in main

  • missing (Set[str]) – a collection of keys to be ignored in main

  • check (Callable[..., bool]) – an additional check on the keys of main, which if True will prevent the key from being checked

Returns

the keys and associated types that were missing

in sub. If no keys were missing then None

Return type

Optional[Dict[str, Type]]

static parameter_consistency(target_cls, obj)

Check that obj has all the necessary arguments, and nothing more.

Parameters
  • target_cls (Constructor) – contains the parameters required by subclass

  • obj (Dict[Any, Any]) – collection of potential arguments for subclass

Returns

None if obj contained the correct

set of keys, otherwise KeyValueDiffError is returned which specifies the missing and/or additional arguments in obj

Return type

Optional[KeyValueDiffError]

type_check(target_cls, orchestrator, obj)

Check the arguments for subclass

Exceptions:
Parameters
  • target_cls (Constructor) – instance of Constructor

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

  • obj (Any) – an instance, containing the arguments for subclass

Returns

if TypeCheckError then either

target_cls was not an instance of Constructor or there are issues which would prevent creating the arguments for subclass, otherwise None

Return type

Optional[TypeCheckError]