mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Merge for issue #26367
This commit is contained in:
commit
0911c0d271
4 changed files with 410 additions and 394 deletions
|
@ -922,9 +922,12 @@ 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 not package:
|
||||
raise ImportError('attempted relative import with no known parent '
|
||||
'package')
|
||||
elif package not in sys.modules:
|
||||
msg = ('Parent module {!r} not loaded, cannot perform relative '
|
||||
'import')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue