summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2012-05-18 18:51:11 (GMT)
committerPetri Lehtinen <petri@digip.org>2012-05-18 18:59:49 (GMT)
commit43ae3ceab8dd65d184aef1773714a604984de38e (patch)
tree67f19442c468077fd4e32c8f8f35d6fdbe6234d3 /Lib
parented3639595aabd3913088c830d345e7db88d9060d (diff)
parent8d886046821f1cd43147c340b04ee0f067157749 (diff)
downloadcpython-43ae3ceab8dd65d184aef1773714a604984de38e.zip
cpython-43ae3ceab8dd65d184aef1773714a604984de38e.tar.gz
cpython-43ae3ceab8dd65d184aef1773714a604984de38e.tar.bz2
#14798: pyclbr now raises ImportError instead of KeyError for missing packages
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pyclbr.py2
-rw-r--r--Lib/test/test_pyclbr.py5
2 files changed, 7 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)