Skip to content

gh-159693: Format import errors with no usable search paths - #159830

Open
limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-159693-traceback-empty-path
Open

limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-159693-traceback-empty-path

Conversation

@limadog9

@limadog9 limadog9 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #159693.

When sys.path has no existing directories, the extension-module hint constructs an empty MultiplexedPath and raises FileNotFoundError while formatting the original ModuleNotFoundError.

This also affects the REPL: InteractiveColoredConsole.runcode() calls traceback.format_exception() through its exception hook. I reproduced the secondary exception through that console before the fix and verified that it displays the original import error afterward.

Return without a hint when there are no directories to search. The regression covers both an empty sys.path and a path containing only a nonexistent directory.

Validation on a Linux x86-64 debug build:

  • Both regression cases fail on unmodified main and pass with the fix.
  • ./python -m test -j2 test_traceback test_code test_pyrepl passed (833 test cases, 65 skips).
  • Ruff, NEWS reStructuredText lint, patchcheck, and git diff --check passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

traceback formatting raises FileNotFoundError with empty sys.path

1 participant