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:
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 an

error 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 state

didn’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:
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 dependency

request 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 values

  • max_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
  • target_cls (Parameter) – container of the parent class

  • obj (Dict[Any, Any]) – arguments to instantiate cls

Returns

The constructor for the sub class specified

in obj

Return type

Constructor

classmethod perfunctory_type_check(target_cls, orchestrator, obj, dependent_from_obj=False)

Ensure the Dependent type specified is well formed

Exceptions:
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 issue

with the DependentType, otherwise None

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 a typing.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 a typing.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 be Dependent

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 be

  • orchestrator (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, otherwise KeyValueError containing the reasons why obj cannot be coerced into any of the listed types

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.

Parameters
  • target_cls (Parameter) – state and DependentUnion request

  • arg (Type) – a type option specified within DependentUnion

Returns

state with cls

argument specifying a type option specified in DependentUnion

Return type

Parameter

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 the Orchestrator

class adorn.unit.parameter_value.ParameterValue

Bases: adorn.unit.simple.Simple

Unit for handling an argument for a parameter specified in a constructor

Parameter contains the type and state from the constructor, which ParameterValue 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 of Parameter

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

Parameter

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 of ParameterValue will be returned, otherwise None

Return type

Optional[ParameterValue]