From 6a2ec96c9721bd873ba93cb8c714f61a3e98012f Mon Sep 17 00:00:00 2001 From: adam-azarchs <22033990+adam-azarchs@users.noreply.github.com> Date: Mon, 19 Feb 2018 12:50:28 -0800 Subject: [PATCH] Fix error reporting for parameterless ImportErrors In some cases, a module may raise an ImportError without any arguments, e.g. if not_allowed(): raise ImportError In this case, the exception has no args. This is bad practice, but it happens. Currently, autodoc will crash with IndexError: tuple index out of range --- sphinx/ext/autodoc/importer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/ext/autodoc/importer.py b/sphinx/ext/autodoc/importer.py index db33b4215..857b6a91e 100644 --- a/sphinx/ext/autodoc/importer.py +++ b/sphinx/ext/autodoc/importer.py @@ -179,7 +179,7 @@ def import_object(modname, objpath, objtype='', attrgetter=safe_getattr, warning if isinstance(real_exc, SystemExit): errmsg += ('; the module executes module level statement ' 'and it might call sys.exit().') - elif isinstance(real_exc, ImportError): + elif isinstance(real_exc, ImportError) and real_exc.args: errmsg += '; the following exception was raised:\n%s' % real_exc.args[0] else: errmsg += '; the following exception was raised:\n%s' % traceback_msg