[Python-checkins] peps: PEP 416: add a section about dictproxy, add more links to Python recipes
victor.stinner
python-checkins at python.org
Wed Mar 14 13:55:32 CET 2012
http://hg.python.org/peps/rev/622068a60e50
changeset: 4135:622068a60e50
user: Victor Stinner <vstinner at wyplay.com>
date: Wed Mar 14 13:55:31 2012 +0100
summary:
PEP 416: add a section about dictproxy, add more links to Python recipes
files:
pep-0416.txt | 32 ++++++++++++++++++++++++++++++--
1 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/pep-0416.txt b/pep-0416.txt
--- a/pep-0416.txt
+++ b/pep-0416.txt
@@ -108,15 +108,43 @@
object is not the purpose of this PEP.
+Alternative: dictproxy
+======================
+
+Python has a builtin dictproxy type used by type.__dict__ getter descriptor.
+This type is not public. dictproxy is a read-only view of a dictionary, but it
+is not read-only mapping. If a dictionary is modified, the dictproxy is also
+modified.
+
+dictproxy can be used using ctypes and the Python C API, see for example the
+`make dictproxy object via ctypes.pythonapi and type() (Python recipe 576540)`_
+by Ikkei Shimomura. The recipe contains a test checking that a dictproxy is
+"mutable" (modify the dictionary linked to the dictproxy).
+
+However dictproxy can be useful in some cases, where its mutable property is
+not an issue, to avoid a copy of the dictionary.
+
+
Links
=====
+ * `Issue #14162: PEP 416: Add a builtin frozendict type
+ <http://bugs.python.org/issue14162>`_
* PEP 412: Key-Sharing Dictionary
(`issue #13903 <http://bugs.python.org/issue13903>`_)
* PEP 351: The freeze protocol
* `The case for immutable dictionaries; and the central misunderstanding of PEP 351 <http://www.cs.toronto.edu/~tijmen/programming/immutableDictionaries.html>`_
- * `Frozen dictionaries (Python recipe 414283) <http://code.activestate.com/recipes/414283-frozen-dictionaries/>`_
- by Oren Tirosh
+ * `Frozen dictionaries (Python recipe 414283) <http://code.activestate.com/recipes/414283/>`_
+ by Oren Tirosh. Blacklist approach: inherit from dict and override write
+ methods to raise an exception. It is not truly read-only: it is still
+ possible to call dict methods on such "frozen dictionary" to modify it.
+ * `Implementing an Immutable Dictionary (Python recipe 498072) <http://code.activestate.com/recipes/498072/>`_
+ by Aristotelis Mikropoulos. Similar to frozendict except that it is not
+ truly read-only. It is possible to access to this private internal dict.
+ It does not implement __hash__ and has an implementation issue: it is
+ possible to call again __init__() to modify the mapping.
+ * `make dictproxy object via ctypes.pythonapi and type() (Python recipe
+ 576540) <http://code.activestate.com/recipes/576540/>`_ by Ikkei Shimomura.
* Python security modules implementing read-only object proxies using a C
extension:
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list