]> 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:56:36 +0000 (21:56 +0300)
Lib/pyclbr.py
Lib/test/test_pyclbr.py
Misc/ACKS
Misc/NEWS

index 52cbdd53ab3d106ec53496079c8fd924526f4bc6..65e9fbedfdd1117b11e98cc7ed71b2e9240cb50f 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 3082b29dbce0ab65c320db1fb50312a0b0d05309..e83989e2d8e3f75252c9959ddf4c5afd8e6b00c3 100644 (file)
@@ -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)
index 8aab2bed117c52d7dd70ef585000f30a89f5cc8d..d8ffe35ea21375944c19431099ffca8d5ffdc6cc 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -332,6 +332,7 @@ Lars Marius Garshol
 Dan Gass
 Andrew Gaul
 Stephen M. Gava
+Xavier de Gaye
 Harry Henry Gebel
 Marius Gedminas
 Thomas Gellekum
index 565db1bd24b5c2fb65dad9b5ab47a87cb3aa4bdb..1e7153d0807d4b86f191c0b403d17c664d8b2bd3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -63,6 +63,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 #14829: Fix bisect and range() indexing with large indices
   (>= 2 ** 32) under 64-bit Windows.