RuleChecker Class

class kwhelp.checks.RuleChecker(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]

Class that validates args match a given rule

__init__(rules_all: Optional[Iterable[kwhelp.rules.IRule]] = None, rules_any: Optional[Iterable[kwhelp.rules.IRule]] = None, **kwargs)[source]

Constructor

Parameters
  • rules_all (Iterable[IRule], optional) – List of rules that must all be matched. Defaults to None.

  • rules_any (Iterable[IRule], optional) – List of rules that any one must be matched. Defaults to None.

Keyword Arguments

raise_error (bool, optional) – If True then rules can raise errors when validation fails. Default False.

Raises
  • TypeError – If rule_all is not an iterable object

  • TypeError – If rule_any is not an iterable object

validate_all(*args, **kwargs) bool[source]

Validates all. All *args and **kwargs must match rules_all

Returns

True if all *args and **kwargs are valid; Otherwise, False

Return type

bool

Raises

Exception – If raise_error is True and validation Fails. The type of exception raised is dependend on the IRule that caused validation failure. Most rules raise a ValueError or a TypeError.

validate_any(*args, **kwargs) bool[source]

Validates any. All *args and **kwargs must match on ore more of rules_any

Returns

True if all *args and **kwargs are valid; Otherwise, False

Return type

bool

Raises

Exception – If raise_error is True and validation Fails. The type of exception raised is dependend on the IRule that caused validation failure. Most rules raise a ValueError or a TypeError.

property raise_error: bool

Determines if errors will be raised during validation

If True then errors will be raised when validation fails. Default value is True.

Getter

Gets if errors can be raised.

Setter

Sets if errors can be raised.

property rules_all: Iterable[kwhelp.rules.IRule]

Gets rules passed into rules_all of constructor used for validation of args.

property rules_any: Iterable[kwhelp.rules.IRule]

Gets rules passed into rules_any of constructor used for validation of args.