summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pkgutil.py3
-rw-r--r--Lib/test/test_pkgutil.py9
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index e37ad45..9180eae 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -119,6 +119,9 @@ 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")
else:
importers = map(get_importer, path)
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py
index fc04dcf..2887ce6 100644
--- a/Lib/test/test_pkgutil.py
+++ b/Lib/test/test_pkgutil.py
@@ -176,6 +176,15 @@ class PkgutilTests(unittest.TestCase):
continue
del sys.modules[pkg]
+ def test_walk_packages_raises_on_string_or_bytes_input(self):
+
+ str_input = 'test_dir'
+ with self.assertRaises((TypeError, ValueError)):
+ list(pkgutil.walk_packages(str_input))
+
+ bytes_input = b'test_dir'
+ with self.assertRaises((TypeError, ValueError)):
+ list(pkgutil.walk_packages(bytes_input))
class PkgutilPEP302Tests(unittest.TestCase):