> 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 type_final.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/type_final.patch Example: >>> class FinalizedType: ... __final__=True ... attr = 10 ... def hello(self): ... print("hello") ... >>> FinalizedType.attr=12 TypeError: 'frozendict' object does not support item assignment >>> FinalizedType.hello=print TypeError: 'frozendict' object does not support item assignment (instance do still have a mutable dict) My patch checks for the __final__ class attribute, but the conversion from dict to frozendict may be done by a function or a type method. Creating a read-only type is a different issue, it's just another example of frozendict usage. Victor
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4