FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159693: Format import errors with no usable search paths by limadog9 · Pull Request #159830 · python/cpython · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 14 additions & 0 deletions Lib/test/test_traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5325,6 +5325,20 @@ def test_windows_only_module_error(self):
else:
self.fail("ModuleNotFoundError was not raised")

def test_module_not_found_without_search_paths(self):
importlib.import_module('importlib.resources.readers')
error = ModuleNotFoundError("No module named 'missing_module'",
name='missing_module')
with os_helper.temp_dir() as tmp:
for paths in ([], [os.path.join(tmp, 'missing')]):
with self.subTest(paths=paths):
with support.swap_attr(sys, 'path', paths):
self.assertEqual(
traceback.format_exception_only(error),
["ModuleNotFoundError: No module named "
"'missing_module'\n"],
)

@unittest.skipIf(not importlib.machinery.EXTENSION_SUFFIXES, 'Platform does not support extension modules')
def test_find_incompatible_extension_modules(self):
"""_find_incompatible_extension_modules assumes the last extension in
Expand Down
7 changes: 4 additions & 3 deletions Lib/traceback.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2106,9 +2106,10 @@ def _find_incompatible_extension_module(module_name):
if parent:
traversable = importlib.resources.files(parent)
else:
traversable = importlib.resources.readers.MultiplexedPath(
*map(pathlib.Path, filter(os.path.isdir, sys.path))
)
paths = list(map(pathlib.Path, filter(os.path.isdir, sys.path)))
if not paths:
return
traversable = importlib.resources.readers.MultiplexedPath(*paths)

for entry in traversable.iterdir():
if entry.name.startswith(child + '.') and entry.name.endswith(untagged_suffix):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix formatting of :exc:`ModuleNotFoundError` when :data:`sys.path` contains
no existing directories, including when displaying errors in the REPL.
Loading

Back | FazBrowse Home | New Git URL