[Python-checkins] peps: Update PEP 3154 after PEP 3155 has been accepted.

antoine.pitrou python-checkins at python.org
Fri Dec 2 20:25:16 CET 2011


http://hg.python.org/peps/rev/d54015aaa32b
changeset:   4006:d54015aaa32b
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Dec 02 20:19:29 2011 +0100
summary:
  Update PEP 3154 after PEP 3155 has been accepted.

files:
  pep-3154.txt |  37 ++++++++++++++++---------------------
  1 files changed, 16 insertions(+), 21 deletions(-)


diff --git a/pep-3154.txt b/pep-3154.txt
--- a/pep-3154.txt
+++ b/pep-3154.txt
@@ -71,27 +71,20 @@
 special method (``__getnewargs_ex__`` ?) and a new opcode (NEWOBJEX ?)
 are needed.
 
-Serializing more callable objects
----------------------------------
+Serializing more "lookupable" objects
+-------------------------------------
 
-Currently, only module-global functions are serializable.
-Multiprocessing has custom support for pickling other callables such
-as bound methods [4]_.  This support could be folded in the protocol,
-and made more efficient through a new GETATTR opcode.
+For some kinds of objects, it only makes sense to serialize them by name
+(for example classes and functions).  By default, pickle is only able to
+serialize module-global functions and classes by name.  Supporting other
+kinds of objects, such as unbound methods [4]_, is a common request.
+Actually, third-party support for some of them, such as bound methods,
+is implemented in the multiprocessing module [5]_.
 
-Serializing "pseudo-global" objects
------------------------------------
-
-Objects which are not module-global, but should be treated in a
-similar fashion -- such as unbound methods [5]_ or nested classes --
-cannot currently be pickled (or, rather, unpickled) because the pickle
-protocol does not correctly specify how to retrieve them.  One
-solution would be through the adjunction of a ``__namespace__`` (or
-``__qualname__``) to all class and function objects, specifying the
-full "path" by which they can be retrieved.  For globals, this would
-generally be ``"{}.{}".format(obj.__module__, obj.__name__)``.  Then a
-new opcode can resolve that path and push the object on the stack,
-similarly to the GLOBAL opcode.
+:pep:`3155` now makes it possible to lookup many more objects by name.
+Generalizing the GLOBAL opcode to accept dot-separated names, or adding
+a special GETATTR opcode, would allow the standard pickle implementation
+to support, in an efficient way, all those kinds of objects.
 
 Binary encoding for all opcodes
 -------------------------------
@@ -131,12 +124,12 @@
 .. [3] "pickle/copyreg doesn't support keyword only arguments in __new__":
    http://bugs.python.org/issue4727
 
-.. [4] Lib/multiprocessing/forking.py:
+.. [4] "pickle should support methods":
+   http://bugs.python.org/issue9276
+
+.. [5] Lib/multiprocessing/forking.py:
    http://hg.python.org/cpython/file/baea9f5f973c/Lib/multiprocessing/forking.py#l54
 
-.. [5] "pickle should support methods":
-   http://bugs.python.org/issue9276
-
 
 Copyright
 =========

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list