Primitive types

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


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):

See returns.primitives.container.BaseContainer for examples.


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.


container (Unwrappable) –

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 this way, we do have several typing features that requires that behaviour


Curry Development