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

Skip to content

Commit 397032a

Browse files
committed
Don't use "exec" in find_class(). It's slow, unnecessary, and (as AMK
points out) it doesn't work in JPython Applets.
1 parent 605ebdd commit 397032a

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

Lib/pickle.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,15 +661,14 @@ def load_global(self):
661661
dispatch[GLOBAL] = load_global
662662

663663
def find_class(self, module, name):
664-
env = {}
665-
666664
try:
667-
exec 'from %s import %s' % (module, name) in env
668-
except ImportError:
665+
__import__(module)
666+
mod = sys.modules[module]
667+
klass = getattr(mod, name)
668+
except (ImportError, KeyError, AttributeError):
669669
raise SystemError, \
670670
"Failed to import class %s from module %s" % \
671671
(name, module)
672-
klass = env[name]
673672
return klass
674673

675674
def load_reduce(self):

0 commit comments

Comments
 (0)