Skip to content

bagof.validators.common

Common validators (any, union, etc.)

Classes

IsAny

IsAny(hint: Any = UNSET, compose: bool = False)

Bases: Validator[T]

Validator for Any.

IsNone

IsNone(hint: Any = UNSET, compose: bool = False)

Bases: Validator[NONE]

Validator for None.

IsUnion

IsUnion(*a, **k)

Bases: Validator[T]

Validator for Union.

IsLiteral

IsLiteral(hint: Any = UNSET, compose: bool = False)

Bases: Validator[T]

Validator for Literal.

A value matches by type as well as value, as PEP 586 specifies: True is not a valid Literal[1] even though True == 1, and neither is 1.0.

IsTypeVar

IsTypeVar(hint: Any = UNSET, compose: bool = False)

Bases: Validator[T]

Validator for TypeVar.

IsAnnotated

IsAnnotated(hint: Any = UNSET, compose: bool = False)

Bases: Validator[T]

Validator for Annotated.

Note

Annotated validators look for validators in the metadata of an annotated type hint and apply them in order (if they are composable).

Methods:

register_metadata classmethod
register_metadata(*hints: Unpack[tuple[Any, ...]]) -> ClassDecorator

Decorator to register a validator class for one or more Annotated metadata hints (e.g. re.Pattern).

Distinct from Validator.register, which registers a validator for a type hint in the global registry; this one registers it for a piece of Annotated metadata.

Parameters:

Name Type Description Default
*hints Unpack[tuple[Any, ...]]

One or more metadata hints to register the validator class for.

()

Returns:

Type Description
ClassDecorator

A decorator that registers the validator class for the given metadata hints.