Skip to content

Conversation

spaceone
Copy link

@spaceone spaceone commented Oct 10, 2025

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'"),

Purpose

Users debugging ImportErrors in their python projects can see the human readable traceback instead of a repr() of it.

  • no tests or documentation needed
  • added an entry to CHANGES.rst.
  • added my name to AUTHORS.rst.

`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'"),
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant