diff --git a/AUTHORS b/AUTHORS index 69c224df056..22690031036 100644 --- a/AUTHORS +++ b/AUTHORS @@ -73,6 +73,7 @@ Other contributors, listed alphabetically, are: * Joel Wurtz -- cellspanning support in LaTeX * Hong Xu -- svg support in imgmath extension and various bug fixes * Stephen Finucane -- setup command improvements and documentation +* Daniel Pizetta -- inheritance diagram improvements Many thanks for all contributions! diff --git a/CHANGES b/CHANGES index 32ce56d6bba..c31bba21bdf 100644 --- a/CHANGES +++ b/CHANGES @@ -15,6 +15,7 @@ Features added Bugs fixed ---------- +* #4019: inheritance_diagram AttributeError stoping make process Testing -------- diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 7a1366b2676..6f8256662a7 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -75,14 +75,20 @@ def try_import(objname): try: __import__(objname) return sys.modules.get(objname) # type: ignore - except ImportError: - modname, attrname = module_sig_re.match(objname).groups() # type: ignore + except (ImportError, ValueError): # ValueError,py27 -> ImportError,py3 + matched = module_sig_re.match(objname) # type: ignore + + if not matched: + return None + + modname, attrname = matched.groups() + if modname is None: return None try: __import__(modname) return getattr(sys.modules.get(modname), attrname, None) - except ImportError: + except (ImportError, ValueError): # ValueError,py27 -> ImportError,py3 return None diff --git a/tests/test_ext_inheritance_diagram.py b/tests/test_ext_inheritance_diagram.py index deb04ce157e..ed79729e637 100644 --- a/tests/test_ext_inheritance_diagram.py +++ b/tests/test_ext_inheritance_diagram.py @@ -83,6 +83,15 @@ def test_import_classes(rootdir): with pytest.raises(InheritanceException): import_classes('unknown.Unknown', None) + # got exception InheritanceException for wrong class or module + # not AttributeError (refs: #4019) + with pytest.raises(InheritanceException): + import_classes('unknown', '.') + with pytest.raises(InheritanceException): + import_classes('unknown.Unknown', '.') + with pytest.raises(InheritanceException): + import_classes('.', None) + # a module having no classes classes = import_classes('sphinx', None) assert classes == []