modelity.constraints
- class modelity.constraints.Ge(min_inclusive: int | float)
Bases:
ConstraintGreater-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).
- __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).
- class modelity.constraints.Gt(min_exclusive: int | float)
Bases:
ConstraintGreater-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).
- __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).
- class modelity.constraints.Le(max_inclusive: Any)
Bases:
ConstraintLess-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).
- __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).
- class modelity.constraints.LenRange(min_length: int, max_length: int)
Bases:
ConstraintLength 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).
- __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).
- class modelity.constraints.Lt(max_exclusive: Any)
Bases:
ConstraintLess-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).
- __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).
- class modelity.constraints.MaxLen(max_length: int)
Bases:
ConstraintMaximum length constraint.
Can be used with sized types, like containers,
byteorstr.- __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).
- __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).
- class modelity.constraints.MinLen(min_length: int)
Bases:
ConstraintMinimum length constraint.
Can be used with sized types, like containers,
byteorstr.- __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).
- __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).
- class modelity.constraints.Range(min: Gt | Ge, max: Lt | Le)
Bases:
ConstraintRange constraint.
Used to set allowed value range for a numeric field using one of
LtorGtfor minimum value, and one ofLtorLefor 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).
- __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).
- class modelity.constraints.Regex(pattern: str)
Bases:
ConstraintRegular 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).
- __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).