adorn.unit.parameter_value module
Handle an argument for a parameter specified in the constructor of a class
- class adorn.unit.parameter_value.Dependent
Bases:
adorn.unit.parameter_value.ParameterValueDependentallows for a parameter to leverage information from other parameters.- classmethod check_args(target_cls, orchestrator)
Ensure type level args are correct
- Exceptions:
MalformedDependencyError:the
Dependenttype didn’t specify the appropriate number of arguments
MissingLiteralError:the first argument, zero based counting, wasn’t a
typing.Literal
UnaryLiteralError:typing.Literalspecifies more than one argument
MalformedLiteralError:typing.Literalwrapped a value that wasn’t of typeDict[str, str]
- Parameters
target_cls (Parameter) – parameter that is dependent on state in the constructor
orchestrator (Orchestrator) – container of types, used to check the argument specified in the
typing.Literal
- Returns
TypeCheckErrorspecifying anerror with the type level dependent argument, otherwise
None
- Return type
Optional[TypeCheckError]
- classmethod check_literal_dict(target_cls, obj, dependent_from_obj=False)
Ensure literal dict is logical given the class and local state
- Exceptions:
ExtraLiteralError:typing.Literalrequested state that weren’t part of the constructor of the parameter
TooDeepLiteralError:typing.Literalrequested state that was more than one layer deep.
- Parameters
target_cls (Parameter) – container of the local state and dependency request
obj (Dict[Any, Any]) – arguments for the parameter
dependent_from_obj (bool) – if
True, the request is grabbing instantiated values, otherwise configured values
- Returns
TypeCheckErrorif the request for statedidn’t work with the state that existed, otherwise
None
- Return type
Optional[TypeCheckError]
- classmethod check_literal_dict_keys(target_cls, literal_dict, args)
Ensure all requested args exist in local state
- Exceptions:
MissingDependencyError:typing.Literalrequested state that wasn’t specified in the local state
- Parameters
target_cls (Parameter) – container parameter’s state
literal_dict (Dict[str, str]) – dependency request
args (Dict[str, Any]) – local state
- Returns
TypeCheckErrorif the dependencyrequest can’t be fulfilled by the local state, otherwise
None
- Return type
Optional[TypeCheckError]
- static get_args(target_cls, literal_dict, dependent_from_obj=False, max_depth=None)
Map the key in literal_dict to its requested dependent state
- Parameters
target_cls (Parameter) – container of the local state
literal_dict (Dict[str, str]) – the request for dependent state
dependent_from_obj (bool) – if
True, the request is grabbing instantiated values, otherwise configured valuesmax_depth (Optional[int]) – the level at which local state will be inspected
- Returns
relevant local state needed by the parameter
- Return type
Dict[str, Any]
- static get_constructor(target_cls, obj)
Generate
Constructorfor relevant sub-type- Parameters
- Returns
- The constructor for the sub class specified
in
obj
- Return type
- classmethod perfunctory_type_check(target_cls, orchestrator, obj, dependent_from_obj=False)
Ensure the Dependent type specified is well formed
- Exceptions:
see
check_argssee
general_check
- Parameters
target_cls (Parameter) – specification of the parameter and its associated state
orchestrator (Orchestrator) – container of types, used to check nested types
obj (Dict[Any, Any]) – the arguments to construct the parameter
dependent_from_obj (bool) – if
True, the request is grabbing instantiated values, otherwise configured values
- Returns
TypeCheckErrorif there was an issuewith the
DependentType, otherwiseNone
- Return type
Optional[TypeCheckError]
- class adorn.unit.parameter_value.DependentFromObj
Bases:
Generic[adorn.unit.complex._T,adorn.unit.parameter_value.DictStrStr],adorn.unit.parameter_value.DependentParameter that requires local state that is known after instantiation
The first argument must be a
Complex, that requires state, known after construction, from the constructor. The second argument is atyping.Literal[Dict[str, str]]where the keys specifies the names of the dependent parameters and the values are the state needed from the constructor.
- class adorn.unit.parameter_value.DependentTypeCheck
Bases:
Generic[adorn.unit.complex._T,adorn.unit.parameter_value.DictStrStr],adorn.unit.parameter_value.DependentParameter that requires local state that is known before instantiation
The first argument must be a
Complex, that requires state, known before construction, from the constructor. The second argument is atyping.Literal[Dict[str, str]]where the keys specifies the names of the dependent parameters and the values are the state needed from the constructor.
- class adorn.unit.parameter_value.DependentUnion
Bases:
Generic[adorn.unit.parameter_value._DependentT,adorn.unit.complex._T],adorn.unit.parameter_value.DependentSimilar to
typing.Union, but only accepts two arguments, where the zeroth argument must beDependent- classmethod get_parameter(target_cls, orchestrator, obj)
Type Check the given
objagainst all potential types- Parameters
target_cls (Parameter) – state and list of potential types
objcould beorchestrator (Orchestrator) – container of all types, typically used to recurse nested types
obj (Dict[Any, Any]) – arguments for one of the listed types
- Returns
- either a
Parameterwhich wraps the type objcan be coerced into, otherwiseKeyValueErrorcontaining the reasons whyobjcannot be coerced into any of the listed types
- either a
- Return type
Union[Parameter, KeyValueError]
- static get_parameter_subtype(target_cls, arg)
Generate an Parameter where we update the
clsarg with a type option.
- class adorn.unit.parameter_value.Identity
Bases:
adorn.unit.parameter_value.ParameterValueIgnore the additional state in the
ParameterWe extract the type information from
Parameterand pass off the object back to theOrchestrator
- class adorn.unit.parameter_value.ParameterValue
Bases:
adorn.unit.simple.SimpleUnitfor handling an argument for a parameter specified in a constructorParametercontains the type and state from the constructor, whichParameterValueallows you to utilize when type checking or instantiating the argument associated with the parameter- contains(obj, orchestrator)
Check if the
objis an instance ofParameter- Parameters
obj (Any) – potentially an instance of
Parameterorchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
True,objis an instance of
- if
- Return type
bool
- get(key, orchestrator)
Get the relevant class to handle the given
Parameterinstance.- Parameters
key (Any) – potentially an instance of
Parameter`orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
keyis an instance of Parameterthen a subclass ofParameterValuewill be returned, otherwiseNone
- if
- Return type
Optional[ParameterValue]