Skip to content

Commit

Permalink
Merge pull request #4532 from dpizetta/1.7-release
Browse files Browse the repository at this point in the history
Fix #4019: exception treatment for AttributeError stopping make process
  • Loading branch information
tk0miya authored Feb 2, 2018
2 parents 0a9d655 + aacc986 commit 48b4c37
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features added

Bugs fixed
----------
* #4019: inheritance_diagram AttributeError stoping make process

Testing
--------
Expand Down
12 changes: 9 additions & 3 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
9 changes: 9 additions & 0 deletions tests/test_ext_inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == []
Expand Down

0 comments on commit 48b4c37

Please sign in to comment.