Skip to content

Constraints

Bases: ConstraintCollection

__eq__ method descriptor

__eq__(value) -> bool

Return self==value.

__ge__ method descriptor

__ge__(value)

Return self>=value.

__getitem__ method descriptor

__getitem__(key) -> Constraint

Return self[key].

__init__

__init__() -> None

__iter__

__iter__() -> Iterator[Constraint]

__le__ method descriptor

__le__(value)

Return self<=value.

__len__ method descriptor

__len__() -> int

Return len(self).

__repr__ method descriptor

__repr__() -> str

Return repr(self).

__str__ method descriptor

__str__() -> str

Return str(self).

add_constraint method descriptor

add_constraint(constraint: Constraint, name: str | None = None) -> None

Add a constraint to the collection.

Parameters:

Name Type Description Default
constraint Constraint

The constraint to be added.

required
name str

The name of the constraint to be added.

None

ctypes method descriptor

ctypes() -> list[Comparator]

Get all unique constraint types identified using their comparator.

decode builtin

decode(data: bytes, env: Environment) -> Expression

Deserialize an expression from binary constraint data.

Parameters:

Name Type Description Default
data bytes

Encoded blob from encode().

required

Returns:

Type Description
Expression

Expression reconstructed from the constraint context.

Raises:

Type Description
DecodeError

If decoding fails due to corruption or incompatibility.

deserialize builtin

deserialize(data: bytes, env: Environment) -> Expression

Alias for decode().

See decode() for usage.

encode method descriptor

encode(compress: bool | None = True, level: int | None = 3) -> bytes

Serialize the constraint collection to a binary blob.

Parameters:

Name Type Description Default
compress bool

Whether to compress the result. Default is True.

True
level int

Compression level (0–9). Default is 3.

3

Returns:

Type Description
bytes

Encoded representation of the constraints.

Raises:

Type Description
IOError

If serialization fails.

equal_contents method descriptor

equal_contents(other: ConstraintCollection) -> bool

Check whether this constraints has equal contents as other.

Parameters:

Name Type Description Default
other ConstraintCollection
required

Returns:

Type Description
bool

get method descriptor

get(item: int | str) -> Constraint

Get a constraint for its name or index.

items method descriptor

items() -> ConstraintCollectionIterator

Iterate over all items ((name, constraint)) in the collection.

remove method descriptor

remove(item: int | str) -> Constraint

Remove a constraint for its name or index.

serialize method descriptor

serialize(compress: bool | None = True, level: int | None = 3) -> bytes

Alias for encode().

See encode() for details.