--- a/mercurial/demandimport.py Tue Sep 27 21:56:00 2016 +0900
+++ b/mercurial/demandimport.py Mon Sep 26 23:28:57 2016 +0900
@@ -191,11 +191,16 @@
def processfromitem(mod, attr):
"""Process an imported symbol in the import statement.
- If the symbol doesn't exist in the parent module, it must be a
- module. We set missing modules up as _demandmod instances.
+ If the symbol doesn't exist in the parent module, and if the
+ parent module is a package, it must be a module. We set missing
+ modules up as _demandmod instances.
"""
symbol = getattr(mod, attr, nothing)
+ nonpkg = getattr(mod, '__path__', nothing) is nothing
if symbol is nothing:
+ if nonpkg:
+ # do not try relative import, which would raise ValueError
+ raise ImportError('cannot import name %s' % attr)
mn = '%s.%s' % (mod.__name__, attr)
if mn in ignore:
importfunc = _origimport