summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libpickle.tex
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2004-05-05 04:54:37 (GMT)
committerFred Drake <fdrake@acm.org>2004-05-05 04:54:37 (GMT)
commit0de77d1d6e899ee98d4ddfb1ac3272b0f69b1199 (patch)
treeb27b0b01c36a3a448a437ca6621ea7f282a4c0ab /Doc/lib/libpickle.tex
parent04d92c37f20fbf1ef4d7a862715ba3eb57e684b8 (diff)
downloadcpython-0de77d1d6e899ee98d4ddfb1ac3272b0f69b1199.zip
cpython-0de77d1d6e899ee98d4ddfb1ac3272b0f69b1199.tar.gz
cpython-0de77d1d6e899ee98d4ddfb1ac3272b0f69b1199.tar.bz2
- note that __getinitargs__() is only for old-style classes
- describe __getnewargs__() (closes SF bug #873246)
Diffstat (limited to 'Doc/lib/libpickle.tex')
-rw-r--r--Doc/lib/libpickle.tex19
1 files changed, 17 insertions, 2 deletions
diff --git a/Doc/lib/libpickle.tex b/Doc/lib/libpickle.tex
index 8816838..e6e8c7c 100644
--- a/Doc/lib/libpickle.tex
+++ b/Doc/lib/libpickle.tex
@@ -448,8 +448,8 @@ for more details.
When a pickled class instance is unpickled, its \method{__init__()}
method is normally \emph{not} invoked. If it is desirable that the
-\method{__init__()} method be called on unpickling, a class can define
-a method \method{__getinitargs__()}, which should return a
+\method{__init__()} method be called on unpickling, an old-style class
+can define a method \method{__getinitargs__()}, which should return a
\emph{tuple} containing the arguments to be passed to the class
constructor (i.e. \method{__init__()}). The
\method{__getinitargs__()} method is called at
@@ -458,6 +458,21 @@ the instance.
\withsubitem{(copy protocol)}{\ttindex{__getinitargs__()}}
\withsubitem{(instance constructor)}{\ttindex{__init__()}}
+New-style types can provide a \method{__getnewargs__()} method that is
+used for protocol 2. Implementing this method is needed if the type
+establishes some internal invariants when the instance is created, or
+if the memory allocation is affected by the values passed to the
+\method{__new__()} method for the type (as it is for tuples and
+strings). Instances of a new-style type \class{C} are created using
+
+\begin{alltt}
+obj = C.__new__(C, *\var{args})
+\end{alltt}
+
+where \var{args} is the result of calling \method{__getnewargs__()} on
+the original object; if there is no \method{__getnewargs__()}, an
+empty tuple is assumed.
+
\withsubitem{(copy protocol)}{
\ttindex{__getstate__()}\ttindex{__setstate__()}}
\withsubitem{(instance attribute)}{