Issue #892902: Fixed pickling recursive objects.
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 299de16..1b3196f 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -402,7 +402,13 @@
write(REDUCE)
if obj is not None:
- self.memoize(obj)
+ # If the object is already in the memo, this means it is
+ # recursive. In this case, throw away everything we put on the
+ # stack, and fetch the object back from the memo.
+ if id(obj) in self.memo:
+ write(POP + self.get(self.memo[id(obj)][0]))
+ else:
+ self.memoize(obj)
# More new special cases (that work with older protocols as
# well): when __reduce__ returns a tuple with 4 or 5 items,