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 handleConstructor
instances.- static check_parameter_order(target_cls)
Ensure
parameter_order
specifies all the parameters.- Parameters
target_cls (Constructor) –
subclass
specifies aparameter_order
- Returns
- if
parameter_order
is complete then
None
, otherwiseParameterOrderError
, which specifies the additional and/or missing parameters inparameter_order
- if
- Return type
Optional[ParameterOrderError]
- contains(obj, orchestrator)
Check if the
obj
is an instance ofConstructor
- Parameters
obj (Any) – potentially an instance of
Constructor
orchestrator (Orchestrator) – this is unused
- Returns
- if
True
,obj
is an instance of
- if
- 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 constructororchestrator (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
- if all the args type check then
- 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 thesubclass
is used to determine which subclass ofConstructorValue
to use. Ifconstructor_type
isNone
thenBaseConstructorValue
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 ofConstructorValue
will be returned, otherwiseNone
- if
- Return type
Optional[ConstructorValue]
- static get_kv(main, alter_value, sub, missing, check=<function ConstructorValue.<lambda>>)
Generate the difference in keys between
main
andsub
.- 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 resultsub (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 ifTrue
will prevent the key from being checked
- Returns
- the keys and associated types that were missing
in
sub
. If no keys were missing thenNone
- 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
ifobj
contained the correctset of keys, otherwise
KeyValueDiffError
is returned which specifies the missing and/or additional arguments inobj
- Return type
Optional[KeyValueDiffError]
- type_check(target_cls, orchestrator, obj)
Check the arguments for
subclass
- Exceptions:
WrongTypeError
:target_cls
was not an instance ofConstructor
- 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 ofConstructor
or there are issues which would prevent creating the arguments forsubclass
, otherwiseNone
- if
- Return type
Optional[TypeCheckError]