extensions: extract the 'importh' closure as normal function
There is no reason for this to be a closure so we extract it for clarity.
--- a/mercurial/extensions.py Fri Mar 11 15:40:58 2016 -0800
+++ b/mercurial/extensions.py Fri Mar 11 10:24:54 2016 +0000
@@ -71,6 +71,14 @@
exc.filename = path # python does not fill this
raise
+def _importh(name):
+ """import and return the <name> module"""
+ mod = __import__(name)
+ components = name.split('.')
+ for comp in components[1:]:
+ mod = getattr(mod, comp)
+ return mod
+
def load(ui, name, path):
if name.startswith('hgext.') or name.startswith('hgext/'):
shortname = name[6:]
@@ -87,20 +95,14 @@
# conflicts with other modules
mod = loadpath(path, 'hgext.%s' % name)
else:
- def importh(name):
- mod = __import__(name)
- components = name.split('.')
- for comp in components[1:]:
- mod = getattr(mod, comp)
- return mod
try:
- mod = importh("hgext.%s" % name)
+ mod = _importh("hgext.%s" % name)
except ImportError as err:
ui.debug('could not import hgext.%s (%s): trying %s\n'
% (name, err, name))
if ui.debugflag:
ui.traceback()
- mod = importh(name)
+ mod = _importh(name)
# Before we do anything with the extension, check against minimum stated
# compatibility. This gives extension authors a mechanism to have their