I just created a version of mine of frozendict and I discovered that there’s a PEP discussing about a frozenmap.
There are some differences I’d like to discuss:
-
the PEP propose to add it to
collectionsmodule. IMHO for symmetry withsetandfrozenset, it should be added tobuiltins -
the PEP propose the introduction of
frozenmap.including(key, value),frozenmap.excluding(key)andfrozenmap.union(mapping=None, **kw)for creating newfrozenmaps with new keys, updated keys or removed keys. On the contrary, myfrozendictsimply implements__add__()and__sub__(), so you can do, for example:
frozendict({"Sulla": "Marco", 2: 3}) + {"Sulla": "Marò", 4: 7, 5: 1}
# frozendict({'Sulla': 'Marò', 2: 3, 4: 7, 5: 1})
frozendict({"Sulla": "Marco", 2: 3}) - [2]
# frozendict({'Sulla': 'Marco'})
-
The PEP propose a
frozenmap.mutating()for returning a mutatable version of thefrozenmap, that can be used in a context. What are the advantage against a simpledict(myfrozenmap)? -
The PEP does not want to preserve the insertion order, like
dictdoes from CPython 3.6. Probablyfrozendictis much slower, since its implementation is in pure Python and it usesMappingProxyType, but at least the API is completely conformant to thedictAPI and insertion is preserved.