immutabledict

class immutabledict.immutabledict(*args: Any, **kwargs: Any)

An immutable wrapper around dictionaries that implements the complete collections.Mapping interface.

It can be used as a drop-in replacement for dictionaries where immutability is desired.

set(key: _K, value: Any) immutabledict[_K, _V]

Return a new immutabledict where the item at the given key is set to to the given value. If there is already an item at the given key it will be replaced.

Parameters:
  • key – the key for which we want to set a value

  • value – the value we want to use

Returns:

the new immutabledict with the key set to the given value

delete(key: _K) immutabledict[_K, _V]

Return a new immutabledict without the item at the given key.

Parameters:

key – the key of the item you want to remove in the returned immutabledict

Raises:

[KeyError] – a KeyError is raised if there is no item at the given key

Returns:

the new immutabledict without the item at the given key

update(_dict: Dict[_K, _V]) immutabledict[_K, _V]

Similar to dict.update() but returning an immutabledict.

Returns:

the updated immutabledict

discard(key: _K) immutabledict[_K, _V]

Return a new immutabledict without the item at the given key, if present.

Parameters:

key – the key of the item you want to remove in the returned immutabledict

Returns:

the new immutabledict without the item at the given key, or a reference to itself if the key is not present