summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/pyclbr.py2
-rw-r--r--Lib/test/test_pyclbr.py5
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS4
4 files changed, 12 insertions, 0 deletions
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py
index 4cd85b9..9ec05ee 100644
--- a/Lib/pyclbr.py
+++ b/Lib/pyclbr.py
@@ -130,6 +130,8 @@ def _readmodule(module, path, inpackage=None):
parent = _readmodule(package, path, inpackage)
if inpackage is not None:
package = "%s.%s" % (inpackage, package)
+ if not '__path__' in parent:
+ raise ImportError('No package named {}'.format(package))
return _readmodule(submodule, parent['__path__'], package)
# Search the path for the module
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 3082b29..e83989e 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -167,6 +167,11 @@ class PyclbrTest(TestCase):
cm('email.parser')
cm('test.test_pyclbr')
+ def test_issue_14798(self):
+ # test ImportError is raised when the first part of a dotted name is
+ # not a package
+ self.assertRaises(ImportError, pyclbr.readmodule_ex, 'asyncore.foo')
+
def test_main():
run_unittest(PyclbrTest)
diff --git a/Misc/ACKS b/Misc/ACKS
index fc65795..4a6d7f0 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -361,6 +361,7 @@ Lars Marius Garshol
Dan Gass
Andrew Gaul
Stephen M. Gava
+Xavier de Gaye
Harry Henry Gebel
Marius Gedminas
Thomas Gellekum
diff --git a/Misc/NEWS b/Misc/NEWS
index db88500..1c3841b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,10 @@ Core and Builtins
Library
-------
+- Issue #14798: Fix the functions in pyclbr to raise an ImportError
+ when the first part of a dotted name is not a package. Patch by
+ Xavier de Gaye.
+
- Issue #12098: multiprocessing on Windows now starts child processes
using the same sys.flags as the current process. Initial patch by
Sergey Mezentsev.