summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/lib/libpickle.tex13
-rw-r--r--Lib/pickle.py3
-rw-r--r--Misc/NEWS3
3 files changed, 15 insertions, 4 deletions
diff --git a/Doc/lib/libpickle.tex b/Doc/lib/libpickle.tex
index dc6edff..d4a54cd 100644
--- a/Doc/lib/libpickle.tex
+++ b/Doc/lib/libpickle.tex
@@ -237,15 +237,20 @@ remembers which objects the pickler has already seen, so that shared
or recursive objects pickled by reference and not by value. This
method is useful when re-using picklers.
-\strong{Note:} \method{clear_memo()} is only available on the picklers
-created by \module{cPickle}. In the \module{pickle} module, picklers
-have an instance variable called \member{memo} which is a Python
-dictionary. So to clear the memo for a \module{pickle} module
+\begin{notice}
+Prior to Python 2.3, \method{clear_memo()} was only available on the
+picklers created by \refmodule{cPickle}. In the \module{pickle} module,
+picklers have an instance variable called \member{memo} which is a
+Python dictionary. So to clear the memo for a \module{pickle} module
pickler, you could do the following:
\begin{verbatim}
mypickler.memo.clear()
\end{verbatim}
+
+Code that does not need to support older versions of Python should
+simply use \method{clear_memo()}.
+\end{notice}
\end{methoddesc}
It is possible to make multiple calls to the \method{dump()} method of
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 541624a..5837884 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -115,6 +115,9 @@ class Pickler:
self.memo = {}
self.bin = bin
+ def clear_memo(self):
+ self.memo.clear()
+
def dump(self, object):
self.save(object)
self.write(STOP)
diff --git a/Misc/NEWS b/Misc/NEWS
index 903e5b0..3d55574 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -99,6 +99,9 @@ Extension modules
Library
+- The pickle.Pickler class grew a clear_memo() method to mimic that
+ provided by cPickle.Pickler.
+
- difflib's SequenceMatcher class now does a dynamic analysis of
which elements are so frequent as to constitute noise. For
comparing files as sequences of lines, this generally works better