You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
traceback formatting raises FileNotFoundError with empty sys.path #159693
On CPython 3.15.0, formatting a ModuleNotFoundError raises a second exception when sys.path contains no existing directory.
importsysimporttracebackimportimportlib.resources.readers# Load dependencies before clearing sys.path.sys.path[:] = []
error=ModuleNotFoundError(
"No module named 'example_missing'",
name="example_missing",
)
print(traceback.format_exception_only(error))
Expected: Expected: A formatted ModuleNotFoundError. (["ModuleNotFoundError: No module named 'example_missing'\n"])
Actual: exception raised (FileNotFoundError: MultiplexedPath must contain at least one path)
The same condition formats successfully on CPython 3.14.8. A path containing only nonexistent directories also triggers the failure; adding an existing directory prevents it.
I would personally think it's weird to have no sys.path at all but the fix should be fairly simple so it's fine to fix this as well. Did you encounter this in a legitimate session btw?
Yeah we don't wan't to do defensive programming actually. I honestly can't imagine a situation where you would empty your path for a long time. However, what I can expect is:
Empty sys.path for some reasons
Do something to fill it with some other stuff
Then hit an exception.
And the traceback formatting fails for some reason.
I don't know if format_exception_only is called and if it raises, then is ignored in the interpreter somewhere and rewritten in C only just in case, but if we use format_exception_only implicitly when raising exceptions, then I would accept a fix. If we don't use traceback for formatting exceptions in the REPL or elsewhere, I would rather reject the fix.
General rule: please don't report issues found by LLMs if they are not realistic in general (hence my question about a real situatio happening).
Activity
picnixz commentedon Oct 19, 2026
I would personally think it's weird to have no
sys.pathat all but the fix should be fairly simple so it's fine to fix this as well. Did you encounter this in a legitimate session btw?heikkitoivonen commentedon Oct 19, 2026
I was adding support for 3.15.0 on my https://pythoncomplexity.com/ site, and Claude/Codex found this when working on unit tests.
picnixz commentedon Oct 19, 2026
Yeah we don't wan't to do defensive programming actually. I honestly can't imagine a situation where you would empty your path for a long time. However, what I can expect is:
I don't know if
format_exception_onlyis called and if it raises, then is ignored in the interpreter somewhere and rewritten in C only just in case, but if we useformat_exception_onlyimplicitly when raising exceptions, then I would accept a fix. If we don't usetracebackfor formatting exceptions in the REPL or elsewhere, I would rather reject the fix.General rule: please don't report issues found by LLMs if they are not realistic in general (hence my question about a real situatio happening).