Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8be9a11

Browse files
committed
Restore two features of the original 1.4 pickle:
- which_module() search __main__ last; - load_inst() no longer checks that the classname really refers to a class.
1 parent faeae5c commit 8be9a11

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/pickle.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class can define a method __getinitargs__, which should return a
128128
I have no answers. Garbage Collection may also become a problem here.)
129129
"""
130130

131-
__version__ = "1.7" # Code version
131+
__version__ = "1.8" # Code version
132132

133133
from types import *
134134
from copy_reg import *
@@ -538,7 +538,8 @@ def whichmodule(cls, clsname):
538538
import sys
539539

540540
for name, module in sys.modules.items():
541-
if hasattr(module, clsname) and \
541+
if name != '__main__' and \
542+
hasattr(module, clsname) and \
542543
getattr(module, clsname) is cls:
543544
break
544545
else:
@@ -677,9 +678,9 @@ def load_inst(self):
677678
module = self.readline()[:-1]
678679
name = self.readline()[:-1]
679680
klass = self.find_class(module, name)
680-
if (type(klass) is not ClassType):
681-
raise SystemError, "Imported object %s from module %s is " \
682-
"not a class" % (name, module)
681+
## if (type(klass) is not ClassType):
682+
## raise SystemError, "Imported object %s from module %s is " \
683+
## "not a class" % (name, module)
683684

684685
value = apply(klass, args)
685686
self.append(value)

0 commit comments

Comments
 (0)