adrn / gala

Galactic and gravitational dynamics in Python
http://gala.adrian.pw
MIT License
130 stars 56 forks source link

Can ImmutableDict be replaced with MappingProxyType? #308

Open nstarman opened 2 years ago

nstarman commented 2 years ago

The latter is built into python.

adrn commented 2 years ago

In reading a bit more about MappingProxyType, I came across this discussion: https://stackoverflow.com/questions/41795116/difference-between-mappingproxytype-and-pep-416-frozendict

Given that ImmutableDict is pretty lightweight to maintain, I don't know that it's worth it. If you have a stronger opinion can you say more? Have you been using MappingProxyType yourself?

nstarman commented 2 years ago

No strong opinion. Just minimizing private API. I use MappingProxyType anywhere I want to make an immutable dict linked to a dict I don't want changed. I find it particularly useful as the output of a property. It can't be pickled, but that's really a plus, because it's tied to the original dict.