mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #26367: Have importlib.__init__() raise RuntimeError when
'level' is specified but no __package__. This brings the function inline with builtins.__import__(). Thanks to Manuel Jacob for the patch.
This commit is contained in:
parent
e10d370a92
commit
4f38cb41fe
4 changed files with 381 additions and 371 deletions
|
@ -922,7 +922,7 @@ def _sanity_check(name, package, level):
|
|||
raise TypeError('module name must be str, not {}'.format(type(name)))
|
||||
if level < 0:
|
||||
raise ValueError('level must be >= 0')
|
||||
if package:
|
||||
if level > 0:
|
||||
if not isinstance(package, str):
|
||||
raise TypeError('__package__ not set to a string')
|
||||
elif package not in sys.modules:
|
||||
|
|
|
@ -207,6 +207,11 @@ class RelativeImports:
|
|||
with self.assertRaises(KeyError):
|
||||
self.__import__('sys', level=1)
|
||||
|
||||
def test_relative_import_no_package_exists_absolute(self):
|
||||
with self.assertRaises(SystemError):
|
||||
self.__import__('sys', {'__package__': '', '__spec__': None},
|
||||
level=1)
|
||||
|
||||
|
||||
(Frozen_RelativeImports,
|
||||
Source_RelativeImports
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue