Skip to main content

Frozen OrderedDict.

Project description

An immutable wrapper around an OrderedDict.

FrozenOrderedDict was inspired by https://pypi.python.org/pypi/frozendict/ (and borrows some code from it). With regards to immutability, it solves the same problems:

  1. Because dictionaries are mutable, they are not hashable and cannot be used in sets or as dictionary keys.

  2. Nasty bugs can and do occur when mutable data structures are passed around.

It can be initialized just like a dict or OrderedDict. However, be advised that just like with OrderedDict, keyword arguments are not recommended since their insertion order is arbitrary.

Once instantiated, an instance of FrozenOrderedDict cannot be altered, since it does not implement the MutableMapping interface.

It does implement the Mapping interface, so can be used just like a normal dictionary in most cases.

In order to modify the contents of a FrozenOrderedDict, a new instance must be created. The easiest way to do that is by calling the .copy() method. It will return a new instance of FrozenOrderedDict initialized using the following steps:

  1. A copy of the wrapped OrderedDict instance will be created.

  2. If any arguments or keyword arguments are passed to the .copy() method, they will be used to create another OrderedDict instance, which will then be used to update the copy made in step #1.

  3. Finally, self.__class__() will be called, passing the copy as the only argument.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

frozenordereddict-1.1.0.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file frozenordereddict-1.1.0.tar.gz.

File metadata

File hashes

Hashes for frozenordereddict-1.1.0.tar.gz
Algorithm Hash digest
SHA256 b872be64b6c35ce915a47aaec10b5085d580aa5dbc81a2f5647648090c02f42f
MD5 80aee471272738fadec666db6a8d9418
BLAKE2b-256 1dd1f8e5581f8d4a9b38b073d4048c635c0c149f39397358f94fbc2054c50482

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page