[Python-Dev] Add a frozendict builtin type (original) (raw)
Victor Stinner victor.stinner at haypocalc.com
Tue Feb 28 12:45:54 CET 2012
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I think you need to elaborate on your use cases further, ...
A frozendict can be used as a member of a set or as a key in a dictionary.
For example, frozendict is indirectly needed when you want to use an object as a key of a dict, whereas one attribute of this object is a dict. Use a frozendict instead of a dict for this attribute answers to this problem.
frozendict helps also in threading and multiprocessing.
--
... and explain what additional changes would be needed, such as allowing frozendict instances as dict attributes in order to create truly immutable objects in pure Python code. In current Python, you can't create a truly immutable object without dropping down to a C extension:
Using frozendict in for type dictionary might be a use case, but please don't focus on this example. There is currently a discussion on python-ideas about this specific use case. I first proposed to use frozendict in type.new, but then I proposed something completly different: add a flag to a set to deny any modification of the type. The flag may be set using "final = True" in the class body for example.
Victor
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]