Implement appropriate __getnewargs__ for all immutable subclassable builtin
types. The special handling for these can now be removed from save_newobj().
Add some testing for this.
Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
diff --git a/Lib/pickle.py b/Lib/pickle.py
index e36e6a6..739c24f 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -191,6 +191,7 @@
self.memo = {}
self.proto = int(proto)
self.bin = proto >= 1
+ self.fast = 0
def clear_memo(self):
"""Clears the pickler's "memo".
@@ -230,6 +231,8 @@
# But there appears no advantage to any other scheme, and this
# scheme allows the Unpickler memo to be implemented as a plain (but
# growable) array, indexed by memo key.
+ if self.fast:
+ return
memo_len = len(self.memo)
self.write(self.put(memo_len))
self.memo[id(obj)] = memo_len, obj
@@ -378,14 +381,7 @@
if getnewargs:
args = getnewargs() # This bette not reference obj
else:
- # XXX These types should each grow a __getnewargs__
- # implementation so this special-casing is unnecessary.
- for cls in int, long, float, complex, str, UnicodeType, tuple:
- if cls and isinstance(obj, cls):
- args = (cls(obj),)
- break
- else:
- args = ()
+ args = ()
save = self.save
write = self.write