# HG changeset patch # User Pierre-Yves David # Date 1457691894 0 # 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 -r 3c90090320ad -r d5512a0a8ad6 mercurial/extensions.py --- 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 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