adorn.unit.constructor_value module
Different ways to handle instances of Constructor
- class adorn.unit.constructor_value.BaseConstructorValue
Bases:
adorn.unit.constructor_value.ConstructorValueVanilla way of type checking and instantiating
Constructorinstances
- class adorn.unit.constructor_value.ConstructorValue
Bases:
adorn.unit.simple.SimpleUnitthat contains all the ways to handleConstructorinstances.- static check_parameter_order(target_cls)
Ensure
parameter_orderspecifies all the parameters.- Parameters
target_cls (Constructor) –
subclassspecifies 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
objis an instance ofConstructor- Parameters
obj (Any) – potentially an instance of
Constructororchestrator (Orchestrator) – this is unused
- Returns
- if
True,objis 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
Constructororchestrator (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
Constructorinstance.The
constructor_typeattached to thesubclassis used to determine which subclass ofConstructorValueto use. Ifconstructor_typeisNonethenBaseConstructorValuewill be returned- Parameters
key (Any) – potentially an instance of
Constructor`orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
keyis an instance of Constructorthen a subclass ofConstructorValuewill 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
mainandsub.- Parameters
main (Dict[str, Any]) – a dict, whose keys are considered necessary
alter_value (Callable[..., type]) – an alteration performed to a value of
mainbefore it is added to the returned resultsub (Dict[str, Any]) – a dict which is checked that it contains the keys in
mainmissing (Set[str]) – a collection of keys to be ignored in
maincheck (Callable[..., bool]) – an additional check on the keys of
main, which ifTruewill 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
objhas all the necessary arguments, and nothing more.- Parameters
target_cls (Constructor) – contains the parameters required by
subclassobj (Dict[Any, Any]) – collection of potential arguments for
subclass
- Returns
Noneifobjcontained the correctset of keys, otherwise
KeyValueDiffErroris 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_clswas not an instance ofConstructor
- Parameters
target_cls (Constructor) – instance of
Constructororchestrator (Orchestrator) – container of all types, typically used to recurse down nested types
obj (Any) – an instance, containing the arguments for
subclass
- Returns
- if
TypeCheckErrorthen either target_clswas not an instance ofConstructoror there are issues which would prevent creating the arguments forsubclass, otherwiseNone
- if
- Return type
Optional[TypeCheckError]