mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37444: Update differing exception between builtins and importlib (GH-14869)
Imports now raise `TypeError` instead of `ValueError` for relative import failures. This makes things consistent between `builtins.__import__` and `importlib.__import__` as well as using a more natural import for the failure. https://bugs.python.org/issue37444 Automerge-Triggered-By: @brettcannon
This commit is contained in:
parent
8e568ef266
commit
c5fa44944e
9 changed files with 134 additions and 108 deletions
|
@ -156,7 +156,7 @@ class RelativeImports:
|
|||
{'__name__': 'pkg', '__path__': ['blah']})
|
||||
def callback(global_):
|
||||
self.__import__('pkg')
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(ImportError):
|
||||
self.__import__('', global_, fromlist=['top_level'],
|
||||
level=2)
|
||||
self.relative_import_test(create, globals_, callback)
|
||||
|
@ -167,7 +167,7 @@ class RelativeImports:
|
|||
globals_ = {'__package__': 'pkg'}, {'__name__': 'pkg.module'}
|
||||
def callback(global_):
|
||||
self.__import__('pkg')
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(ImportError):
|
||||
self.__import__('', global_, fromlist=['top_level'],
|
||||
level=2)
|
||||
self.relative_import_test(create, globals_, callback)
|
||||
|
|
|
@ -375,7 +375,7 @@ class ResolveNameTests:
|
|||
|
||||
def test_no_package(self):
|
||||
# .bacon in ''
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(ImportError):
|
||||
self.util.resolve_name('.bacon', '')
|
||||
|
||||
def test_in_package(self):
|
||||
|
@ -390,7 +390,7 @@ class ResolveNameTests:
|
|||
|
||||
def test_escape(self):
|
||||
# ..bacon in spam
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(ImportError):
|
||||
self.util.resolve_name('..bacon', 'spam')
|
||||
|
||||
|
||||
|
@ -518,7 +518,7 @@ class FindSpecTests:
|
|||
with util.temp_module(name, pkg=True) as pkg_dir:
|
||||
fullname, _ = util.submodule(name, subname, pkg_dir)
|
||||
relname = '.' + subname
|
||||
with self.assertRaises(ValueError):
|
||||
with self.assertRaises(ImportError):
|
||||
self.util.find_spec(relname)
|
||||
self.assertNotIn(name, sorted(sys.modules))
|
||||
self.assertNotIn(fullname, sorted(sys.modules))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue