magni.utils.validation._levels module

Module providing the validate_levels function.

Routine listings

validate_levels(name, levels)
Validate containers and mappings as well as contained objects.
magni.utils.validation._levels.validate_levels(name, levels)[source]

Validate containers and mappings as well as contained objects

The present function is meant to valdiate the ‘levels’ of a variable. That is, the value of the variable itself, the values of the second level (in case the value is a list, tuple, or dict), the values of the third level, and so on.

Parameters:
  • name (None) – The name of the variable to be validated.
  • levels (list or tuple) – The list of levels.

See also

magni.utils.validation.validate_generic()
Validate non-numeric objects.
magni.utils.validation.validate_numeric()
Validate numeric objects.

Notes

name must refer to a variable in the parent scope of the function or method decorated by magni.utils.validation.decorate_validation which is closest to the top of the call stack. If name is a string then there must be a variable of that name in that scope. If name is a set-like object then there must be a variable having the first value in that set-like object as name. The remaining values are used as keys/indices on the variable to obtain the variable to be validated. For example, the name (‘name’, 0, ‘key’) refers to the variable “name[0][‘key’]”.

levels is a list containing the levels. The value of the variable is validated against the first level. In case the value is a list, tuple, or dict, the values contained in this are validated against the second level and so on. Each level is itself a list with the first value being either ‘generic’ or ‘numeric’ followed by the arguments that should be passed to the respective function (with the exception of name which is automatically prepended by the present function).

Examples

Every public function and method of the present package (with the exception of the functions of this subpackage itself) validates every argument and keyword argument using the functionality of this subpackage. Thus, for examples of how to use the present function, browse through the code.

magni.utils.validation._levels._validate_level(name, var, levels, index=0)[source]

Validate a level.

Parameters:
  • name (None) – The name of the variable.
  • var (None) – The value of the variable.
  • levels (set-like) – The levels.
  • index (int) – The index of the current level. (the default is 0)