Make try/catch AttributeError less all-encompassing

This commit is contained in:
Matt Westcott 2019-08-19 16:13:35 +01:00 committed by Matt Westcott
parent 3502c38804
commit 96c1152eab

View file

@ -47,17 +47,17 @@ class MovedDefinitionHandler(object):
# in the stack trace
raise e from None
warnings.warn(
"%s has been moved from %s to %s" % (name, self.real_module.__name__, new_module_name),
category=self.warning_class, stacklevel=2
)
warnings.warn(
"%s has been moved from %s to %s" % (name, self.real_module.__name__, new_module_name),
category=self.warning_class, stacklevel=2
)
# load the requested definition from the module named in moved_definitions
new_module = import_module(new_module_name)
definition = getattr(new_module, name)
# load the requested definition from the module named in moved_definitions
new_module = import_module(new_module_name)
definition = getattr(new_module, name)
# stash that definition into the current module so that we don't have to
# redo this import next time we access it
setattr(self.real_module, name, definition)
# stash that definition into the current module so that we don't have to
# redo this import next time we access it
setattr(self.real_module, name, definition)
return definition
return definition