Skip to content

Commit 010b678

Browse files
committed
fix(ext.autodoc): fix logging of tracebacks
`traceback.format_exception()` returns a list of strings containing already newlines. Sphinx just logs the repr of that list, which makes it impossible to read tracebacks easily. the real and helpful exception trace would be: ``` Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/importer.py", line 175, in import_module module = importlib.import_module(modname) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1206, in _gcd_import File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/root/module.py", line 58, in <module> ... AttributeError: 'NoneType' object has no attribute 'lower' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/importer.py", line 269, in import_object module = import_module(modname, try_reload=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/sphinx/ext/autodoc/importer.py", line 187, in import_module raise ImportError(exc, traceback.format_exc()) from exc ImportError: (AttributeError("'NoneType' object has no attribute 'lower'"), ```
1 parent f224e04 commit 010b678

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sphinx/ext/autodoc/importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def _import_from_module_and_path(
281281
# import_module() raises ImportError having real exception obj and
282282
# traceback
283283
real_exc = exc.args[0]
284-
traceback_msg = traceback.format_exception(exc)
284+
traceback_msg = ''.join(traceback.format_exception(exc))
285285
if isinstance(real_exc, SystemExit):
286286
err_parts.append(
287287
'the module executes module level statement '

0 commit comments

Comments
 (0)