Primitive types

We have several utility types that we use for our containers, that can also help end users as well.

Immutable

This class is useful when you need to make some instances immutable (like our containers are).

API Reference

graph TD; Immutable
class Immutable[source]

Bases: object

Helper type for objects that should be immutable.

When applied, each instance becomes immutable. Nothing can be added or deleted from it.

>>> from returns.primitives.types import Immutable
>>> class MyModel(Immutable):
...     ...

>>> model = MyModel()
>>> model.prop = 1
Traceback (most recent call last):
   ...
returns.primitives.exceptions.ImmutableStateError

See returns.primitives.container.BaseContainer for examples.

Exceptions

graph TD; UnwrapFailedError ImmutableStateError Exception --> UnwrapFailedError AttributeError --> ImmutableStateError
exception UnwrapFailedError(container)[source]

Bases: Exception

Raised when a container can not be unwrapped into a meaningful value.

Parameters

container (Unwrappable) –

halted_container
exception ImmutableStateError[source]

Bases: AttributeError

Raised when a container is forced to be mutated.

It is a sublclass of AttributeError for two reasons:

  1. It seems kinda reasonable to expect AttributeError on attribute modification

  2. It is used inside typing.py this way, we do have several typing features that requires that behaviour

See: https://github.com/dry-python/returns/issues/394

Curry Development