Skip to content

bagof.validators.misc

Miscellaneous validators (forbidden values, etc.).

Attributes

IsNotOneOfValidator module-attribute

IsNotOneOfValidator = IsNotOneOf

Deprecated alias for IsNotOneOf.

Every other validator is named IsXxx; the suffix was dropped for consistency.

Classes

IsNotOneOf

IsNotOneOf(forbidden: Iterable[T], hint: Any = UNSET, compose: bool = False)

Bases: Validator[T]

Validator for values not in a forbidden set.

A value is forbidden only when it matches by type as well as value: forbidding 1 does not forbid True, even though the two compare equal.

Example

>>> from bagof.validators.misc import IsNotOneOf
>>> validate = IsNotOneOf(["", "null"])
>>> validate("name")
>>> validate("")
ValueValidationError: IsNotOneOf(): Forbidden value.
|> value = ''

Parameters:

Name Type Description Default
forbidden Iterable[T]

The forbidden values. Need not be hashable.

required
hint Any

The type hint to validate against. If not provided, the default hint for the class is used.

UNSET
compose bool

Whether to compose this validator with others, when they are found in Annotated metadata.

False

Methods: