betty.mutability module

The mutability API.

This provides tools to mark objects as mutable or immutable, and to guard against mutations.

exception betty.mutability.ImmutableError[source]

Bases: MutabilityError, RuntimeError

An error raised because something was unexpectedly immutable.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

exception betty.mutability.MutabilityError[source]

Bases: Exception

A generic mutability API error.

class betty.mutability.Mutable[source]

Bases: object

A generic mutable type that can be marked immutable.

__init__(*args: Any, mutable: bool = True, **kwargs: Any)[source]
assert_immutable() None[source]

Assert that the instance is immutable.

Raises:

MutableError – if the instance is mutable.

assert_mutable() None[source]

Assert that the instance is mutable.

Raises:

ImmutableError – if the instance is immutable.

get_mutable_instances() Iterable[Mutable][source]

Get any other betty.mutability.Mutable instances contained by this one.

immutable() None[source]

Mark the instance immutable.

property is_immutable: bool

Whether the instance is immutable.

property is_mutable: bool

Whether the instance is mutable.

mutable() None[source]

Mark the instance mutable.

exception betty.mutability.MutableError[source]

Bases: MutabilityError, RuntimeError

An error raised because something was unexpectedly mutable.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

betty.mutability.immutable(*instances: Mutable) None[source]

Mark the given instances immutable.

betty.mutability.mutable(*instances: Mutable) None[source]

Mark the given instances mutable.