summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2016-02-20 20:59:36 (GMT)
committerBrett Cannon <brett@python.org>2016-02-20 20:59:36 (GMT)
commit0911c0d27176bb0501b87dd65ebfb47bc3da4e12 (patch)
tree0ad28eb66cc7c7c4846af1f7f44523288c43fb01 /Lib/importlib
parentd9dc53021e11c357592f7ecc4aa9e5dba9bcd359 (diff)
parent4f38cb41fe022c94bb5569c72d8b48020d8c13d4 (diff)
downloadcpython-0911c0d27176bb0501b87dd65ebfb47bc3da4e12.zip
cpython-0911c0d27176bb0501b87dd65ebfb47bc3da4e12.tar.gz
cpython-0911c0d27176bb0501b87dd65ebfb47bc3da4e12.tar.bz2
Merge for issue #26367
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index f0a4e1c..880c493 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -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')