Commits

pv committed d7fba1a

autosummary: fix bug in importing top-level modules

  • Participants
  • Parent commits 6c974ce

Comments (0)

Files changed (1)

sphinx/ext/autosummary/__init__.py

 def _import_by_name(name):
     """Import a Python object given its full name."""
     try:
+        name_parts = name.split('.')
+
         # try first interpret `name` as MODNAME.OBJ
-        name_parts = name.split('.')
-        try:
-            modname = '.'.join(name_parts[:-1])
-            __import__(modname)
-            return getattr(sys.modules[modname], name_parts[-1])
-        except (ImportError, IndexError, AttributeError):
-            pass
+        modname = '.'.join(name_parts[:-1])
+        if modname:
+            try:
+                __import__(modname)
+                return getattr(sys.modules[modname], name_parts[-1])
+            except (ImportError, IndexError, AttributeError):
+                pass
 
         # ... then as MODNAME, MODNAME.OBJ1, MODNAME.OBJ1.OBJ2, ...
         last_j = 0