Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b77dc4ec
Commit
b77dc4ec
authored
Nov 08, 2012
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#11481: merge with 3.2.
parents
60e22b9c
78b18d4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
Doc/library/copy.rst
Doc/library/copy.rst
+2
-2
Doc/library/copyreg.rst
Doc/library/copyreg.rst
+26
-3
No files found.
Doc/library/copy.rst
View file @
b77dc4ec
...
...
@@ -67,8 +67,8 @@ of lists by assigning a slice of the entire list, for example,
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)
...
...
Doc/library/copyreg.rst
View file @
b77dc4ec
...
...
@@ -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 @@ Such constructors may be factory functions or class instances.
: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...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment