Update PEP 3154 after PEP 3155 has been accepted.
This commit is contained in:
parent
3c89c9c913
commit
4ca9074870
39
pep-3154.txt
39
pep-3154.txt
|
@ -71,27 +71,20 @@ arguments can not be pickled (or, rather, unpickled) [3]_. Both a new
|
|||
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 @@ References
|
|||
.. [3] "pickle/copyreg doesn't support keyword only arguments in __new__":
|
||||
http://bugs.python.org/issue4727
|
||||
|
||||
.. [4] Lib/multiprocessing/forking.py:
|
||||
http://hg.python.org/cpython/file/baea9f5f973c/Lib/multiprocessing/forking.py#l54
|
||||
|
||||
.. [5] "pickle should support methods":
|
||||
.. [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
|
||||
|
||||
|
||||
Copyright
|
||||
=========
|
||||
|
|
Loading…
Reference in New Issue