Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immutable/frozen munch #43

Open
worldmind opened this issue Apr 4, 2019 · 1 comment
Open

Immutable/frozen munch #43

worldmind opened this issue Apr 4, 2019 · 1 comment

Comments

@worldmind
Copy link

Hi, I am searching a best type for config data, usually it is nested dict, but on my opinion config must:

  1. have dot notation for readability,
  2. be immutable for safe using (config is global variable).
    Can Munch be immutable?

P.S. I found https://github.com/cdgriffith/Box/ but not sure that it popular = good tested.

@jaraco
Copy link

jaraco commented Oct 11, 2020

You might also consider jaraco.collections, which adds attribute access for items on any mapping:

$ pip-run --use-pep517 jaraco.collections frozendict
Collecting frozendict
  Using cached frozendict-1.2.tar.gz (2.6 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Collecting jaraco.collections
  Using cached jaraco.collections-3.0.0-py2.py3-none-any.whl (9.4 kB)
Collecting jaraco.classes
  Using cached jaraco.classes-3.1.0-py2.py3-none-any.whl (5.7 kB)
Collecting six>=1.7.0
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting jaraco.text
  Using cached jaraco.text-3.2.0-py2.py3-none-any.whl (8.1 kB)
Collecting jaraco.functools
  Using cached jaraco.functools-3.0.1-py3-none-any.whl (6.7 kB)
Collecting more-itertools
  Using cached more_itertools-8.5.0-py3-none-any.whl (44 kB)
Building wheels for collected packages: frozendict
  Building wheel for frozendict (PEP 517) ... done
  Created wheel for frozendict: filename=frozendict-1.2-py3-none-any.whl size=3148 sha256=b127942c3dbb2d8e958462f10dbae7e2e67c45b6bd21f9d6edaa81aa76d1bd5c
  Stored in directory: /Users/jaraco/Library/Caches/pip/wheels/5b/fa/ab/0a80360debb57b95f092356ee3a075bbbffc631b9813136599
Successfully built frozendict
Installing collected packages: more-itertools, six, jaraco.functools, jaraco.text, jaraco.classes, jaraco.collections, frozendict
Successfully installed frozendict-1.2 jaraco.classes-3.1.0 jaraco.collections-3.0.0 jaraco.functools-3.0.1 jaraco.text-3.2.0 more-itertools-8.5.0 six-1.15.0
Python 3.9.0 (v3.9.0:9cf6752276, Oct  5 2020, 11:29:23) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import frozendict
>>> import jaraco.collections
>>> class FrozenDictAttrs(frozendict.frozendict, jaraco.collections.ItemsAsAttributes):
...     pass
... 
>>> fd = FrozenDictAttrs(a=1, b=2)
>>> fd.a
1
>>> fd['a'] = 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'FrozenDictAttrs' object does not support item assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants