[Python-Dev] Add a frozendict builtin type (original) (raw)
Victor Stinner victor.stinner at gmail.com
Thu Mar 1 15:54:01 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 ]
> Here are my real-world use cases. Not for security, but for safety and > performance reasons (I've built by own RODict and ROList modeled after > dictproxy): > > - Global, but immutable containers, e.g. as class members
I attached typefinal.patch to the issue #14162 to demonstrate how frozendict can be used to implement a "read-only" type. Last version: http://bugs.python.org/file24696/typefinal.patch Oh, hmm. I rather meant something like that: """ class Foo: somemapping = frozendict( blah=1, blub=2 ) or as a variant: def zonk(somedefault=frozendict(...)): ... or simply a global object: baz = frozendict(someimmutablemapping) """
Ah yes, frozendict is useful for such cases.
I'm not sure about your final types. I'm using slots = () for such things
You can still replace an attribute value if a class defines slots:
class A: ... slots=('x',) ... x = 1 ... A.x=2 A.x 2
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 ]