Numeric
DecimalPlaces
DecimalPlaces(max_places, *, message=None, code=None) — caps the digits after the decimal point. Accepts int, float, decimal.Decimal, and numeric strings. Trailing zeros count as places (so Decimal("1.50") reports 2 places).
Even · Odd
Integer parity checks. Reject bool and non-integer numerics.
Interval
Interval(*, gt=None, ge=None, lt=None, le=None, message=None, code=None) — comparable bounds. Any combination of bounds is valid. All bounds accept Ref.
IsFinite · IsInfinite · IsNan
Predicate-backed math checks for floats. Use bare instances.
MultipleOf
MultipleOf(multiple_of, *, message=None, code=None) — value must be exactly divisible. Accepts Ref.
NonNegative · Positive · Negative
Pre-instantiated Interval shortcuts: ge=0, gt=0, and lt=0 respectively. Use bare.
score: Annotated[int, NonNegative]
amount: Annotated[float, Positive]
delta: Annotated[float, Negative]
NonZero
NonZero(*, message=None, code=None) — rejects values equal to zero. Works with any numeric that supports ==.
Port
Port(*, message=None, code=None) — integer in [1, 65535].
PowerOfTwo
PowerOfTwo(*, message=None, code=None) — positive integer that is a power of two (1, 2, 4, 8, 16, …). Common for ML batch sizes, ring buffers, and cache-aligned allocations.