summaryrefslogtreecommitdiffstats
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-01-29 17:58:45 (GMT)
committerGuido van Rossum <guido@python.org>2003-01-29 17:58:45 (GMT)
commit5d9113d8be81596bc93f2b1a37f57e5110d39a77 (patch)
treef7bdf7fc9aa5afbf967e9e110baea0e4cdd9ffec /Lib/pickle.py
parentd3590f937f4493445beeb253e5048771d1663ab7 (diff)
downloadcpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.zip
cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.gz
cpython-5d9113d8be81596bc93f2b1a37f57e5110d39a77.tar.bz2
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.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py12
1 files changed, 4 insertions, 8 deletions
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 @@ class Pickler:
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 @@ class Pickler:
# 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 @@ class Pickler:
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