[Python-checkins] cpython (merge 3.2 -> default): #14798: pyclbr now raises ImportError instead of KeyError for missing packages
petri.lehtinen
python-checkins at python.org
Fri May 18 21:03:24 CEST 2012
http://hg.python.org/cpython/rev/2f51c15bbc56
changeset: 77043:2f51c15bbc56
parent: 77040:6286dd856252
parent: 77042:895246f1a06a
user: Petri Lehtinen <petri at digip.org>
date: Fri May 18 21:51:11 2012 +0300
summary:
#14798: pyclbr now raises ImportError instead of KeyError for missing packages
files:
Lib/pyclbr.py | 2 ++
Lib/test/test_pyclbr.py | 5 +++++
Misc/ACKS | 1 +
Misc/NEWS | 4 ++++
4 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/Lib/pyclbr.py b/Lib/pyclbr.py
--- a/Lib/pyclbr.py
+++ b/Lib/pyclbr.py
@@ -130,6 +130,8 @@
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
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -167,6 +167,11 @@
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
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -361,6 +361,7 @@
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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -38,6 +38,10 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list