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

Skip to content

Commit efd3a3a

Browse files
committed
Implement find_class() without exec statement.
1 parent c699553 commit efd3a3a

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)