diff --git a/Doc/library/pkgutil.rst b/Doc/library/pkgutil.rst index 5d4ff34ba029a0..e8d458f83ad07e 100644 --- a/Doc/library/pkgutil.rst +++ b/Doc/library/pkgutil.rst @@ -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. @@ -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. diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py index dccbec52aa731e..4b446da3a41bae 100644 --- a/Lib/pkgutil.py +++ b/Lib/pkgutil.py @@ -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. @@ -97,8 +97,8 @@ 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. @@ -106,8 +106,8 @@ def iter_modules(path=None, prefix=''): 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) diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py index d095f440a99f63..0f3190b4277d06 100644 --- a/Lib/test/test_pkgutil.py +++ b/Lib/test/test_pkgutil.py @@ -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"))