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
collections
module. IMHO for symmetry withset
andfrozenset
, 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 newfrozenmap
s with new keys, updated keys or removed keys. On the contrary, myfrozendict
simply 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
dict
does from CPython 3.6. Probablyfrozendict
is much slower, since its implementation is in pure Python and it usesMappingProxyType
, but at least the API is completely conformant to thedict
API and insertion is preserved.