frozenlist2

class frozenlist2.frozenlist

An immutable list.

The frozenlist class has identical behavior to the list class, with the following exceptions:

  • Any attempt to modify the list will raise NotImplementedError.

  • The list is hashable, if and only if all list elements are hashable.

Why not tuple?

Although the standard tuple provides an immutable sequence, it has the unfortunate property that a tuple is never equal to a list, even when the tuple/list lengths and all elements are equal.

This has negative implications for the ergonomics of an API designed to return immutable data. Developers typically use lists as the default choice for an iterable; if an API instead returns a tuple in order to expose immutable data, callers must be vigilant to recall that tuples rather than lists are in use, and forgetting this can lead to subtle bugs.

frozenlist avoids this problem, so that developers can work with immutable sequences without having to fight their natural inclination to think in terms of lists.