Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
jacobtylerwalls committed Sep 15, 2024
commit fd24f8794c3fdd5b38f3e8934e1dec9c9889b52f
5 changes: 3 additions & 2 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,10 +1109,11 @@ def _get_parent_path(self):
module = sys.modules[parent_module_name]
except KeyError as e:
raise ModuleNotFoundError(
f"{parent_module_name} must be imported before finding {self._name}.",
f"{parent_module_name!r} must be imported before finding {self._name!r}.",
name=parent_module_name,
) from e
return getattr(module, path_attr_name)
else:
return getattr(module, path_attr_name)

def _recalculate(self):
# If the parent's path has changed, recalculate _path
Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_importlib/test_namespace_pkgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,11 @@ class NamespaceSubpackageSameName(NamespacePackageTest):

def test_namespace_subpackage_shares_name_with_directory(self):
submodule_path = 'project4.foo'
msg = 'project4 must be imported before finding project4.foo.'
with self.assertRaisesRegex(ModuleNotFoundError, msg):
with self.assertRaises(ModuleNotFoundError) as cm:
importlib.machinery.PathFinder.find_spec(submodule_path)

self.assertEqual(cm.exception.name, 'project4')


class ReloadTests(NamespacePackageTest):
paths = ['portion1']
Expand Down