From 4f38cb41fe022c94bb5569c72d8b48020d8c13d4 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sat, 20 Feb 2016 12:52:06 -0800 Subject: 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. --- Lib/importlib/_bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/importlib/_bootstrap.py') diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 6f62bb35fe..1b3b4305a2 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -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: -- cgit v1.2.1