mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
#14798: pyclbr now raises ImportError instead of KeyError for missing packages
This commit is contained in:
parent
491ef97f75
commit
280e9f7ce5
4 changed files with 12 additions and 0 deletions
|
@ -128,6 +128,8 @@ def _readmodule(module, path, inpackage=None):
|
||||||
parent = _readmodule(package, path, inpackage)
|
parent = _readmodule(package, path, inpackage)
|
||||||
if inpackage is not None:
|
if inpackage is not None:
|
||||||
package = "%s.%s" % (inpackage, package)
|
package = "%s.%s" % (inpackage, package)
|
||||||
|
if not '__path__' in parent:
|
||||||
|
raise ImportError('No package named {}'.format(package))
|
||||||
return _readmodule(submodule, parent['__path__'], package)
|
return _readmodule(submodule, parent['__path__'], package)
|
||||||
|
|
||||||
# Search the path for the module
|
# Search the path for the module
|
||||||
|
|
|
@ -188,6 +188,11 @@ class PyclbrTest(TestCase):
|
||||||
cm('email.parser')
|
cm('email.parser')
|
||||||
cm('test.test_pyclbr')
|
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():
|
def test_main():
|
||||||
run_unittest(PyclbrTest)
|
run_unittest(PyclbrTest)
|
||||||
|
|
|
@ -297,6 +297,7 @@ Lars Marius Garshol
|
||||||
Dan Gass
|
Dan Gass
|
||||||
Andrew Gaul
|
Andrew Gaul
|
||||||
Stephen M. Gava
|
Stephen M. Gava
|
||||||
|
Xavier de Gaye
|
||||||
Harry Henry Gebel
|
Harry Henry Gebel
|
||||||
Marius Gedminas
|
Marius Gedminas
|
||||||
Thomas Gellekum
|
Thomas Gellekum
|
||||||
|
|
|
@ -60,6 +60,10 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #14832: fixed the order of the argument references in the error
|
||||||
message produced by unittest's assertItemsEqual.
|
message produced by unittest's assertItemsEqual.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue