From 280e9f7ce5c441658c48680299e3e40ec76b03ed Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Fri, 18 May 2012 21:51:11 +0300 Subject: [PATCH] #14798: pyclbr now raises ImportError instead of KeyError for missing packages --- Lib/pyclbr.py | 2 ++ Lib/test/test_pyclbr.py | 5 +++++ Misc/ACKS | 1 + Misc/NEWS | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py index 97f74f1b28..b8f71ae6b6 100644 --- a/Lib/pyclbr.py +++ b/Lib/pyclbr.py @@ -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 diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py index 6aa96d53ea..7bdc555cd2 100644 --- a/Lib/test/test_pyclbr.py +++ b/Lib/test/test_pyclbr.py @@ -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) diff --git a/Misc/ACKS b/Misc/ACKS index 18c304ebfc..ca1f5dcadf 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 4908f39c2b..088d1e4e9e 100644 --- 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. -- 2.40.0