mercurial/demandimport.py
changeset 30022 26a4e46af2bc
parent 30021 16a09ae318b4
child 30156 75c71c533977
equal deleted inserted replaced
30021:16a09ae318b4 30022:26a4e46af2bc
   189         globalname = globals.get('__name__')
   189         globalname = globals.get('__name__')
   190 
   190 
   191         def processfromitem(mod, attr):
   191         def processfromitem(mod, attr):
   192             """Process an imported symbol in the import statement.
   192             """Process an imported symbol in the import statement.
   193 
   193 
   194             If the symbol doesn't exist in the parent module, it must be a
   194             If the symbol doesn't exist in the parent module, and if the
   195             module. We set missing modules up as _demandmod instances.
   195             parent module is a package, it must be a module. We set missing
       
   196             modules up as _demandmod instances.
   196             """
   197             """
   197             symbol = getattr(mod, attr, nothing)
   198             symbol = getattr(mod, attr, nothing)
       
   199             nonpkg = getattr(mod, '__path__', nothing) is nothing
   198             if symbol is nothing:
   200             if symbol is nothing:
       
   201                 if nonpkg:
       
   202                     # do not try relative import, which would raise ValueError
       
   203                     raise ImportError('cannot import name %s' % attr)
   199                 mn = '%s.%s' % (mod.__name__, attr)
   204                 mn = '%s.%s' % (mod.__name__, attr)
   200                 if mn in ignore:
   205                 if mn in ignore:
   201                     importfunc = _origimport
   206                     importfunc = _origimport
   202                 else:
   207                 else:
   203                     importfunc = _demandmod
   208                     importfunc = _demandmod