skshapes.input_validation.notnone_rules

Not-None rules.

This module define decorators that allows to do some checks for functions that can be called by different arguments combinations. For example, a function can be called with one of the arguments a, b or c but not with more than one of them. This can be done with the one_and_only_one decorator:

from skshapes.input_validation import one_and_only_one


@one_and_only_one(["a", "b", "c"])
def foo(a=None, b=None, c=None):
    pass


foo(a=1)  # OK
foo(b=1)  # OK
foo(c=1)  # OK
foo(a=1, b=1)  # InputStructureError
Traceback (most recent call last):
    ...
skshapes.errors.InputStructureError: One and only one of the parameters ['a', 'b', 'c'] must be not None and they must be passed as keyword arguments.

Decorators already implemented:

  • one_and_only_one : one and only one of the parameters must be not None

  • no_more_than_one : no more than one of the parameters must be not None

Functions

generator_notnone_rule(rule)

Not-None rules decorator generator.

no_more_than_one(parameters)

Checker for less than one not None parameter.

one_and_only_one(parameters)

Checker for only one not None parameter.

rule_no_more_than_one(not_none, parameters)

Rule that checks that no more than one of the parameters is not None.

rule_one_and_only_one(not_none, parameters)

Rule that checks that one and only one of the parameters is not None.