mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix autodoc: ImportError is replaced by AttributeError for deeper module
This commit is contained in:
parent
daac35cda7
commit
e07731e7b1
1
CHANGES
1
CHANGES
@ -30,6 +30,7 @@ Bugs fixed
|
||||
* #5348: download reference to remote file is not displayed
|
||||
* #5282: html theme: ``pygments_style`` of theme was overrided by ``conf.py``
|
||||
by default
|
||||
* autodoc: ImportError is replaced by AttributeError for deeper module
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -168,13 +168,15 @@ def import_object(modname, objpath, objtype='', attrgetter=safe_getattr, warning
|
||||
|
||||
try:
|
||||
module = None
|
||||
exc_on_importing = None
|
||||
objpath = list(objpath)
|
||||
while module is None:
|
||||
try:
|
||||
module = import_module(modname, warningiserror=warningiserror)
|
||||
logger.debug('[autodoc] import %s => %r', modname, module)
|
||||
except ImportError:
|
||||
except ImportError as exc:
|
||||
logger.debug('[autodoc] import %s => failed', modname)
|
||||
exc_on_importing = exc
|
||||
if '.' in modname:
|
||||
# retry with parent module
|
||||
modname, name = modname.rsplit('.', 1)
|
||||
@ -193,6 +195,10 @@ def import_object(modname, objpath, objtype='', attrgetter=safe_getattr, warning
|
||||
object_name = attrname
|
||||
return [module, parent, object_name, obj]
|
||||
except (AttributeError, ImportError) as exc:
|
||||
if isinstance(exc, AttributeError) and exc_on_importing:
|
||||
# restore ImportError
|
||||
exc = exc_on_importing
|
||||
|
||||
if objpath:
|
||||
errmsg = ('autodoc: failed to import %s %r from module %r' %
|
||||
(objtype, '.'.join(objpath), modname))
|
||||
|
Loading…
Reference in New Issue
Block a user