blob: 407044c4bb288cb4112d1fe93f28faeb19d7ff76 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`copy_reg` --- Register :mod:`pickle` support functions
3============================================================
4
5.. module:: copy_reg
6 :synopsis: Register pickle support functions.
7
Alexandre Vassalotti25ad76c2008-05-11 09:01:51 +00008.. note::
9 The :mod:`copy_reg` module has been renamed to `copyreg` in Python 3.0.
Georg Brandl8ec7f652007-08-15 14:28:01 +000010
11.. index::
12 module: pickle
13 module: cPickle
14 module: copy
15
16The :mod:`copy_reg` module provides support for the :mod:`pickle` and
17:mod:`cPickle` modules. The :mod:`copy` module is likely to use this in the
18future as well. It provides configuration information about object constructors
19which are not classes. Such constructors may be factory functions or class
20instances.
21
22
23.. function:: constructor(object)
24
25 Declares *object* to be a valid constructor. If *object* is not callable (and
26 hence not valid as a constructor), raises :exc:`TypeError`.
27
28
29.. function:: pickle(type, function[, constructor])
30
31 Declares that *function* should be used as a "reduction" function for objects of
32 type *type*; *type* must not be a "classic" class object. (Classic classes are
33 handled differently; see the documentation for the :mod:`pickle` module for
34 details.) *function* should return either a string or a tuple containing two or
35 three elements.
36
37 The optional *constructor* parameter, if provided, is a callable object which
38 can be used to reconstruct the object when called with the tuple of arguments
39 returned by *function* at pickling time. :exc:`TypeError` will be raised if
40 *object* is a class or *constructor* is not callable.
41
42 See the :mod:`pickle` module for more details on the interface expected of
43 *function* and *constructor*.
44