Range

class component_model.range.Range(val: bool | int | float | str | Enum, rng: tuple[Any, Any] | None | Sequence[Never] = tuple(), unit: Unit | None = None)

Bases: object

Utility class to store and handle the variable range of a single-valued variable.

Parameters:
  • val – value for which the range is defined. At least an example value of the same type in base units shall be provided.

  • rng (tuple) = () –

    Optional range of the variable in terms of a tuple of the same type as initial value. Should be specified with units (as string) and is expected in display units.

    • If an empty tuple is specified, the range is automatically determined. That is only possible for float or enum type variables, where the former evaluates to (-inf, inf). Maximum or minimum int values do not exist in Python, such that these always must be provided explicitly. It is not possible to set only one of the elements of the tuple automatically.

    • If None is specified, the initial value is chosen, i.e. no range. None can be applied to the whole tuple or to single elements of the tuple. E.g. (1,None) sets the range to (1, start)

    • For some variable types (e.g. str) no range is expected.

    • Internally, the range is stored in base units. For range checking of a new value, the new value must be converted to base units before check.

  • unit (Unit) – expected Unit (should be determined for start value before range is determined)

__init__(val: bool | int | float | str | Enum, rng: tuple[Any, Any] | None | Sequence[Never] = tuple(), unit: Unit | None = None)

Methods

__init__(val[, rng, unit])

auto_extreme(var)

Return the extreme values of the variable.

check(value[, typ, unit, disp])

Check a value with respect to type and range.

err_code_msg(code)

is_valid_spec(rng, var_len, typ[, level])

Check whether the supplied rng is a valid range specification for a variable.

classmethod auto_extreme(var: bool | int | float | str | Enum | type) tuple[int | float | bool, int | float | bool]

Return the extreme values of the variable.

Parameters:

var – the variable for which to determine the extremes, represented by an instantiated object (example) or by the type itself

Return type:

A tuple containing the minimum and maximum value the given variable can have

classmethod err_code_msg(code: int) str
classmethod is_valid_spec(rng: tuple[Any, ...] | tuple[Any, Any] | None | Sequence[Never], var_len: int, typ: type, level: int = 0) int

Check whether the supplied rng is a valid range specification for a variable. Applies to scalar and compound variable specs. Return 0 (ok) or error code >0 if not ok.

check(value: bool | int | float | str | Enum | None, typ: type = float, unit: Unit | None = None, disp: bool = True) bool

Check a value with respect to type and range.

Parameters:
  • value – the Python value to check with respect to the internally defined Range

  • typ (type) – the expected Python type of the value

  • unit (Unit) – the Unit object related to the variable

  • disp (bool) – denotes whether ‘value’ is in display units (True) or base units (False)