summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-08-30 19:53:48 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-08-30 19:53:48 (GMT)
commitde4ebfe5597d503af097cd51ec51cc70fa79d250 (patch)
treee4995b7c1ebf6126c33d858aaaded300fc93c584 /Lib/importlib/_bootstrap.py
parentce7d4cbc3bb49e331a119df21058e9bbd6f15f83 (diff)
downloadcpython-de4ebfe5597d503af097cd51ec51cc70fa79d250.zip
cpython-de4ebfe5597d503af097cd51ec51cc70fa79d250.tar.gz
cpython-de4ebfe5597d503af097cd51ec51cc70fa79d250.tar.bz2
When the globals argument to importlib.__import__() contained any value for
__package__, it was used. This was incorrect since it could be set to None to represent the fact that a proper value was unknown. Now None will trigger the calculation for __package__. Discovered when running importlib against test_importhooks.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 063f603..bd62c36 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -922,10 +922,10 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0):
if level == 0:
module = _gcd_import(name)
else:
- # __package__ is not guaranteed to be defined.
- try:
- package = globals['__package__']
- except KeyError:
+ # __package__ is not guaranteed to be defined or could be set to None
+ # to represent that it's proper value is unknown
+ package = globals.get('__package__')
+ if package is None:
package = globals['__name__']
if '__path__' not in globals:
package = package.rpartition('.')[0]