[Python-checkins] cpython (merge 3.3 -> default): #11481: merge with 3.3.

ezio.melotti python-checkins at python.org
Thu Nov 8 10:06:36 CET 2012


http://hg.python.org/cpython/rev/20b65b88e0a0
changeset:   80306:20b65b88e0a0
parent:      80300:5d7e7e7e2e82
parent:      80305:87ec3ce3a04e
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Thu Nov 08 11:06:19 2012 +0200
summary:
  #11481: merge with 3.3.

files:
  Doc/library/copy.rst    |   4 ++--
  Doc/library/copyreg.rst |  29 ++++++++++++++++++++++++++---
  2 files changed, 28 insertions(+), 5 deletions(-)


diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst
--- a/Doc/library/copy.rst
+++ b/Doc/library/copy.rst
@@ -67,8 +67,8 @@
 
 Classes can use the same interfaces to control copying that they use to control
 pickling.  See the description of module :mod:`pickle` for information on these
-methods.  The :mod:`copy` module does not use the :mod:`copyreg` registration
-module.
+methods.  In fact, :mod:`copy` module uses the registered pickle functions from
+:mod:`copyreg` module.
 
 .. index::
    single: __copy__() (copy protocol)
diff --git a/Doc/library/copyreg.rst b/Doc/library/copyreg.rst
--- a/Doc/library/copyreg.rst
+++ b/Doc/library/copyreg.rst
@@ -9,9 +9,10 @@
    module: pickle
    module: copy
 
-The :mod:`copyreg` module provides support for the :mod:`pickle` module.  The
-:mod:`copy` module is likely to use this in the future as well.  It provides
-configuration information about object constructors which are not classes.
+The :mod:`copyreg` module offers a way to define fuctions used while pickling
+specific objects.  The :mod:`pickle` and :mod:`copy` modules use those functions
+when pickling/copying those objects.  The module provides configuration
+information about object constructors which are not classes.
 Such constructors may be factory functions or class instances.
 
 
@@ -37,3 +38,25 @@
    :attr:`~pickle.Pickler.dispatch_table` attribute of a pickler
    object or subclass of :class:`pickle.Pickler` can also be used for
    declaring reduction functions.
+
+Example
+-------
+
+The example below would like to show how to register a pickle function and how
+it will be used:
+
+   >>> import copyreg, copy, pickle
+   >>> class C(object):
+   ...     def __init__(self, a):
+   ...         self.a = a
+   ...
+   >>> def pickle_c(c):
+   ...     print("pickling a C instance...")
+   ...     return C, (c.a,)
+   ...
+   >>> copyreg.pickle(C, pickle_c)
+   >>> c = C(1)
+   >>> d = copy.copy(c)
+   pickling a C instance...
+   >>> p = pickle.dumps(c)
+   pickling a C instance...

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


More information about the Python-checkins mailing list