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.ParameterValue
Dependent
allows for a parameter to leverage information from other parameters.- classmethod check_args(target_cls, orchestrator)
Ensure type level args are correct
- Exceptions:
MalformedDependencyError
:the
Dependent
type didn’t specify the appropriate number of arguments
MissingLiteralError
:the first argument, zero based counting, wasn’t a
typing.Literal
UnaryLiteralError
:typing.Literal
specifies more than one argument
MalformedLiteralError
:typing.Literal
wrapped 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
TypeCheckError
specifying 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.Literal
requested state that weren’t part of the constructor of the parameter
TooDeepLiteralError
:typing.Literal
requested 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
TypeCheckError
if 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.Literal
requested 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
TypeCheckError
if 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
Constructor
for 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_args
see
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
TypeCheckError
if 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.Dependent
Parameter 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.Dependent
Parameter 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.Dependent
Similar 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
obj
against all potential types- Parameters
target_cls (Parameter) – state and list of potential types
obj
could 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
Parameter
which wraps the type obj
can be coerced into, otherwiseKeyValueError
containing the reasons whyobj
cannot 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
cls
arg with a type option.
- class adorn.unit.parameter_value.Identity
Bases:
adorn.unit.parameter_value.ParameterValue
Ignore the additional state in the
Parameter
We extract the type information from
Parameter
and pass off the object back to theOrchestrator
- class adorn.unit.parameter_value.ParameterValue
Bases:
adorn.unit.simple.Simple
Unit
for handling an argument for a parameter specified in a constructorParameter
contains the type and state from the constructor, whichParameterValue
allows you to utilize when type checking or instantiating the argument associated with the parameter- contains(obj, orchestrator)
Check if the
obj
is an instance ofParameter
- Parameters
obj (Any) – potentially an instance of
Parameter
orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
True
,obj
is an instance of
- if
- Return type
bool
- get(key, orchestrator)
Get the relevant class to handle the given
Parameter
instance.- Parameters
key (Any) – potentially an instance of
Parameter`
orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
key
is an instance of Parameter
then a subclass ofParameterValue
will be returned, otherwiseNone
- if
- Return type
Optional[ParameterValue]