Skip to content

pfun.immutable.Immutable

Super class that makes subclasses immutable using dataclasses

Examples:

1
2
3
4
5
6
7
>>> class A(Immutable):
...     a: str
>>> class B(A):
...     b: str
>>> b = B('a', 'b')
>>> b.a = 'new value'
AttributeError: <__main__.B object at 0x10f99a0f0> is immutable

clone(self, **kwargs)

Make a shallow copy of an instance, potentially overwriting fields given by kwargs

Examples:

1
2
3
4
5
6
>>> class A(Immutable):
...     a: str
>>> a = A('a')
>>> a2 = a.clone(a='new value')
>>> a2.a
"new value"

Parameters:

Name Type Description Default
kwargs

fields to overwrite

{}

Returns:

Type Description
~T

New instance of same type with copied and overwritten fields