Skip to content

gh-90149: make pkutil path arg less ambiguous #119252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions Doc/library/pkgutil.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ support.
Yields :class:`ModuleInfo` for all submodules on *path*, or, if
*path* is ``None``, all top-level modules on :data:`sys.path`.

*path* should be either ``None`` or a list of paths to look for modules in.
*path* should be either ``None`` or a list of paths (List[str]) to search
for modules.

*prefix* is a string to output on the front of every module name on output.

Expand All @@ -148,7 +149,8 @@ support.
Yields :class:`ModuleInfo` for all modules recursively on
*path*, or, if *path* is ``None``, all accessible modules.

*path* should be either ``None`` or a list of paths to look for modules in.
*path* should be either ``None`` or a list of paths (List[str]) to search
for modules.

*prefix* is a string to output on the front of every module name on output.

Expand Down
12 changes: 6 additions & 6 deletions Lib/pkgutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def walk_packages(path=None, prefix='', onerror=None):
"""Yields ModuleInfo for all modules recursively
on path, or, if path is None, all accessible modules.

'path' should be either None or a list of paths to look for
modules in.
'path' should be either None or a list of paths (List[str]) to search
for modules.

'prefix' is a string to output on the front of every module name
on output.
Expand Down Expand Up @@ -97,17 +97,17 @@ def iter_modules(path=None, prefix=''):
"""Yields ModuleInfo for all submodules on path,
or, if path is None, all top-level modules on sys.path.

'path' should be either None or a list of paths to look for
modules in.
'path' should be either None or a list of paths (List[str]) to search
for modules.

'prefix' is a string to output on the front of every module name
on output.
"""
if path is None:
importers = iter_importers()
elif isinstance(path, str):
raise ValueError("path must be None or list of paths to look for "
"modules in")
raise ValueError("path must be None or a list of paths (List[str]) to"
" search for modules")
else:
importers = map(get_importer, path)

Expand Down
5 changes: 3 additions & 2 deletions Lib/test/test_pkgutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ def test_issue44061_iter_modules(self):
del sys.path[0]
sys.modules.pop(pkg, None)

# assert path must be None or list of paths
expected_msg = "path must be None or list of paths to look for modules in"
# assert path must be None or a list of paths (List[str])
expected_msg = r"path must be None or a list of paths \(List\[str\]\) " \
"to search for modules"
with self.assertRaisesRegex(ValueError, expected_msg):
list(pkgutil.iter_modules("invalid_path"))

Expand Down
Loading