pypz.core.commons.parameters module

class pypz.core.commons.parameters.ExpectedParameter(required: bool, parameter_type: Type[ParameterType], alt_name: str | None = None, description: str | None = None, on_update: Callable[[Any, Any], None] = None)

Bases: Generic[ParameterType]

This is a descriptor class, which describes an instance parameter. To do that you need to describe the parameter on class level (which shall be one of the RegisteredInterface) then you need to refer with the same name as instance variable. Usage:

class TestImpl(Instance):
    required_param = ExpectedParameter(required=True, parameter_type=str)
    optional_param = ExpectedParameter(required=False, parameter_type=str)

    def __init__(self):
        self.required_param = None
        self.optional_param = "defaultValue"

This is equivalent to:

class TestImpl(Instance):
    required_param = RequiredParameter(str)
    optional_param = OptionalParameter(str)

    def __init__(self):
        self.required_param = None
        self.optional_param = "defaultValue"
Parameters:
  • required – true, if parameter required, false if not

  • parameter_type – (str, int, float, set, list, dict, type(None))

  • alt_name – alternative name for the parameter, if specified it acts as reference to the parameter

  • on_update – callback to react on value update

NamePrefix = '__private_instance_parameter__'

This prefix is used to prefix the actual variables created by this descriptor

description: str | None

Short description of the parameter and its intended usage

name: str | None

Alternative name for the parameter. It can be used to define the actual parameter name with having a different variable name.

on_update: Callable[[Any, Any], None]

Callback to execute a specific logic, if the value is changed

to_dict(instance=None) dict
class pypz.core.commons.parameters.OptionalParameter(parameter_type: Type[ParameterType] = None, alt_name: str = None, description: str | None = None, on_update: Callable[[Any, Any], None] = None)

Bases: ExpectedParameter[ParameterType]

Convenience class to represent an optional parameter Usage:

class TestImpl(Instance):
    required_param = RequiredParameter(str)
    optional_param = OptionalParameter(str)
    def __init__(self):
        self.required_param = None
        self.optional_param = "defaultValue"
Parameters:
  • parameter_type – (str, int, float, set, list, dict, type(None))

  • alt_name – alternative name for the parameter, if specified it acts as reference to the parameter

  • on_update – callback to react on value update

class pypz.core.commons.parameters.RequiredParameter(parameter_type: Type[ParameterType] = None, alt_name: str = None, description: str | None = None, on_update: Callable[[Any, Any], None] = None)

Bases: ExpectedParameter[ParameterType]

Convenience class to represent a required parameter Usage:

class TestImpl(Instance):
    required_param = RequiredParameter(str)
    optional_param = OptionalParameter(str)
    def __init__(self):
        self.required_param = None
        self.optional_param = "defaultValue"
Parameters:
  • parameter_type – (str, int, float, set, list, dict, type(None))

  • alt_name – alternative name for the parameter, if specified it acts as reference to the parameter

  • on_update – callback to react on value update

pypz.core.commons.parameters.retrieve_parameters(input_val, parameter_type: Type[ExpectedParameter]) dict[str, ExpectedParameter]

This method attempts to retrieve all described parameters with either public or protected scope. Private scoped parameters are ignored.

Parameters:
  • input_val – object or class to be mapped

  • parameter_type – parameter type to look for

Returns:

dict of parameter names to parameter objects