modelity.constraints

class modelity.constraints.Ge(min_inclusive: int | float)

Bases: Constraint

Greater-or-equal constraint.

Used to specify minimum inclusive value for a numeric field.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(min_inclusive: int | float) None
__match_args__ = ('min_inclusive',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

min_inclusive: int | float

The minimum inclusive value set for this constraint.

class modelity.constraints.Gt(min_exclusive: int | float)

Bases: Constraint

Greater-than constraint.

Used to specify minimum exclusive value for a numeric field.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(min_exclusive: int | float) None
__match_args__ = ('min_exclusive',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

min_exclusive: int | float

The minimum exclusive value set for this constraint.

class modelity.constraints.Le(max_inclusive: Any)

Bases: Constraint

Less-or-equal constraint.

Used to set maximum inclusive value for a numeric field.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(max_inclusive: Any) None
__match_args__ = ('max_inclusive',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

max_inclusive: Any

The maximum inclusive value set for this constraint.

class modelity.constraints.LenRange(min_length: int, max_length: int)

Bases: Constraint

Length range constraint.

Combines both minimum and maximum length constraints.

Added in version 0.28.0.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(min_length: int, max_length: int) None
__match_args__ = ('min_length', 'max_length')
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

max_length: int

Maximum length.

min_length: int

Minimum length.

class modelity.constraints.Lt(max_exclusive: Any)

Bases: Constraint

Less-than constraint.

Used to set maximum exclusive value for a numeric field.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(max_exclusive: Any) None
__match_args__ = ('max_exclusive',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

max_exclusive: Any

The maximum exclusive value set for this constraint.

class modelity.constraints.MaxLen(max_length: int)

Bases: Constraint

Maximum length constraint.

Can be used with sized types, like containers, byte or str.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(max_length: int) None
__match_args__ = ('max_length',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

max_length: int

Maximum length.

class modelity.constraints.MinLen(min_length: int)

Bases: Constraint

Minimum length constraint.

Can be used with sized types, like containers, byte or str.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(min_length: int) None
__match_args__ = ('min_length',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

min_length: int

Minimum length.

class modelity.constraints.Range(min: Gt | Ge, max: Lt | Le)

Bases: Constraint

Range constraint.

Used to set allowed value range for a numeric field using one of Lt or Gt for minimum value, and one of Lt or Le for maximum value.

Added in version 0.28.0.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: Any) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(min: Gt | Ge, max: Lt | Le) None
__match_args__ = ('min', 'max')
__repr__() str

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

max: Lt | Le

The maximum value.

min: Gt | Ge

The minimum value.

class modelity.constraints.Regex(pattern: str)

Bases: Constraint

Regular expression constraint.

Allows values matching given regular expression and reject all other. Can only operate on strings.

__abstractmethods__ = frozenset({})
__call__(errors: list[Error], loc: Loc, value: str) bool

Run all checks against given value.

Returns True and does not modify error list if value satisfies the constraint.

Returns False and adds one or more errors to error list if value does not satisfy the constraint.

Parameters:
  • errors – Mutable list of errors.

  • loc – The current location in the model.

  • value – The validated value.

__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(pattern: str) None
__match_args__ = ('pattern',)
__repr__()

Return text representation of the constraint.

This is used when rendering constraints in error messages.

__setattr__(name, value)

Implement setattr(self, name, value).

pattern: str

Regular expression pattern.