CheckValues
- class plasmapy.utils.decorators.checks.CheckValues(checks_on_return: dict[str, bool] | None = None, **checks: dict[str, bool])[source]
Bases:
CheckBase
A decorator class to ‘check’ — limit/control — the values of input and return arguments to a function or method.
- Parameters:
checks_on_return (Dict[str, bool]) – Specifications for value checks on the return of the function being wrapped. (see check values for valid specifications)
**checks (Dict[str, Dict[str, bool]]) –
Specifications for value checks on the input arguments of the function being wrapped. Each keyword argument in
checks
is the name of a function argument to be checked and the keyword value contains the value check specifications.The value check specifications are defined within a dictionary containing the keys defined below. If the dictionary is empty or omitting keys, then the default value will be assumed for the missing keys.
Key
Type
Description
can_be_negative
[DEFAULT
True
] values can be negativecan_be_complex
[DEFAULT
False
] values can be complex numberscan_be_inf
can_be_nan
none_shall_pass
can_be_zero
[DEFAULT
True
] values can be zero
Notes
Checking of function arguments
*args
and**kwargs
is not supported.
Examples
from plasmapy.utils.decorators.checks import CheckValues @CheckValues( arg1={"can_be_negative": False, "can_be_nan": False}, arg2={"can_be_inf": False}, checks_on_return={"none_shall_pass": True}, ) def foo(arg1, arg2): return None # on a method class Foo: @CheckValues( arg1={"can_be_negative": False, "can_be_nan": False}, arg2={"can_be_inf": False}, checks_on_return={"none_shall_pass": True}, ) def bar(self, arg1, arg2): return None
Attributes Summary
Requested checks on the decorated function's input arguments and/or return.
Methods Summary
__call__
(f)Decorate a function.
Attributes Documentation
- checks
Requested checks on the decorated function’s input arguments and/or return.
Methods Documentation