]> granicus.if.org Git - python/commitdiff
#14798: pyclbr now raises ImportError instead of KeyError for missing packages
authorPetri Lehtinen <petri@digip.org>
Fri, 18 May 2012 18:51:11 +0000 (21:51 +0300)
committerPetri Lehtinen <petri@digip.org>
Fri, 18 May 2012 18:54:25 +0000 (21:54 +0300)
Lib/pyclbr.py
Lib/test/test_pyclbr.py
Misc/ACKS
Misc/NEWS

index 97f74f1b28c67d3dd05919d30b0f9e1d36c2701a..b8f71ae6b64843f38a1284316fa98d34627882dd 100644 (file)
@@ -128,6 +128,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
index 6aa96d53ea42ffffee1da4a9df2d151046040bce..7bdc555cd27b91719feaf74b74f21d0e4d08775b 100644 (file)
@@ -188,6 +188,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)
index 18c304ebfcfa292dcbb5a92ac3c1b90a79317c34..ca1f5dcadf019bcd5b84d867963c8d0be12acb87 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -297,6 +297,7 @@ Lars Marius Garshol
 Dan Gass
 Andrew Gaul
 Stephen M. Gava
+Xavier de Gaye
 Harry Henry Gebel
 Marius Gedminas
 Thomas Gellekum
index 4908f39c2bd94ff8b4e1b934d7950bfd42e2c4b6..088d1e4e9e07953367446d5b0f3ecc610ab15331 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -60,6 +60,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 #14832: fixed the order of the argument references in the error
   message produced by unittest's assertItemsEqual.