summaryrefslogtreecommitdiff
path: root/Lib/pickle.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-17 22:50:45 +0000
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-07-17 22:50:45 +0000
commit1c5b456e00c6fc66e08e98c8e23313ad01509288 (patch)
tree023939839962d5d1a3eee67c5a61a92a82fd676a /Lib/pickle.py
parent72d53c83941c77157517b8db62386fd70d24a566 (diff)
downloadcpython-1c5b456e00c6fc66e08e98c8e23313ad01509288.tar.gz
Issue #5180: Fixed a bug that prevented loading 2.x pickles in 3.x
python when they contain instances of old-style classes.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r--Lib/pickle.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py
index c4fc2c4d1f..372d5b623a 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -1034,19 +1034,15 @@ class _Unpickler:
def _instantiate(self, klass, k):
args = tuple(self.stack[k+1:])
del self.stack[k:]
- instantiated = False
- if (not args and
- isinstance(klass, type) and
- not hasattr(klass, "__getinitargs__")):
- value = _EmptyClass()
- value.__class__ = klass
- instantiated = True
- if not instantiated:
+ if (args or not isinstance(klass, type) or
+ hasattr(klass, "__getinitargs__")):
try:
value = klass(*args)
except TypeError as err:
raise TypeError("in constructor for %s: %s" %
(klass.__name__, str(err)), sys.exc_info()[2])
+ else:
+ value = klass.__new__(klass)
self.append(value)
def load_inst(self):
@@ -1239,14 +1235,7 @@ class _Unpickler:
raise _Stop(value)
dispatch[STOP[0]] = load_stop
-# Helper class for load_inst/load_obj
-
-class _EmptyClass:
- pass
-
-# Encode/decode longs in linear time.
-
-import binascii as _binascii
+# Encode/decode longs.
def encode_long(x):
r"""Encode a long to a two's complement little-endian binary string.