←back to thread

191 points jwilk | 7 comments | | HN request time: 5.129s | source | bottom
1. bilsbie ◴[] No.46230878[source]
Wow weird Mandela effect for me. I really remember this being a built and actually using it.
replies(4): >>46230962 #>>46231000 #>>46231036 #>>46231089 #
2. Qem ◴[] No.46230962[source]
Perhaps you used the frozen dict implementation from the pip installable boltons library: https://boltons.readthedocs.io/en/latest/dictutils.html#bolt...
3. pansa2 ◴[] No.46231000[source]
There was a previous PEP (in 2012) with the exact same title:

https://peps.python.org/pep-0416/

Also one in 2019 for a "frozenmap":

https://peps.python.org/pep-0603/

4. hiddencost ◴[] No.46231036[source]
Perhaps immutabledict?

https://pypi.org/project/immutabledict/

5. aewens ◴[] No.46231089[source]
You may be thinking of the `frozenset()` built in or the third party Python module [frozendict](https://pypi.org/project/frozendict/)?

Personally, I’ve been using a wrapper around `collections.namedtuple` as an underlying data structure to create frozen dictionaries when I’ve needed something like that for a project.

replies(1): >>46231303 #
6. guidopallemans ◴[] No.46231303[source]
When you are making str -> Any dictionaries it's quite likely you're better off with dataclasses or namedtuples anyway.
replies(1): >>46231804 #
7. TheFlyingFish ◴[] No.46231804{3}[source]
That works if you're dealing with a known set of keys (i.e. what most statically-typed languages would call a struct). It falls down if you need something where the keys are unknowable until runtime, like a lookup table.

I do like dataclasses, though. I find them sneaking into my code more and more as time goes on. Having a declared set of properties is really useful, and it doesn't hurt either that they're syntactically nicer to use.