# HG changeset patch # User Pierre-Yves David # Date 2016-03-11 10:24:54 # Node ID d5512a0a8ad6ed260cb8eab84843d47d3048d500 # Parent 3c90090320ad1c9017a9f14019a19f05442f8866 extensions: extract the 'importh' closure as normal function There is no reason for this to be a closure so we extract it for clarity. diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -71,6 +71,14 @@ def loadpath(path, module_name): exc.filename = path # python does not fill this raise +def _importh(name): + """import and return the 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 @@ def load(ui, name, path): # 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