Skip to content

Commit 5cef75b

Browse files
author
guido
committed
Implement find_class() without exec statement.
git-svn-id: http://svn.python.org/projects/python/trunk@7667 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 47effa0 commit 5cef75b

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Lib/pickle.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,12 @@ def load_class(self):
465465
dispatch[CLASS] = load_class
466466

467467
def find_class(self, module, name):
468-
env = {}
469468
try:
470-
exec 'from %s import %s' % (module, name) in env
471-
except ImportError:
469+
klass = getattr(__import__(module), name)
470+
except (ImportError, AttributeError):
472471
raise SystemError, \
473472
"Failed to import class %s from module %s" % \
474473
(name, module)
475-
klass = env[name]
476474
if type(klass) is BuiltinFunctionType:
477475
raise SystemError, \
478476
"Imported object %s from module %s is not a class" % \

0 commit comments

Comments
 (0)