summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2014-03-21 10:58:33 -0400
committerBrett Cannon <brett@python.org>2014-03-21 10:58:33 -0400
commita00c2407caed1fe61bdd92788f7a8eb27fcff969 (patch)
treef86c2e40aa7510e084fbd1a165366abe1385aa99
parent373f0a925bcaed53e7e2eb0406694acb00a03e36 (diff)
downloadcpython-git-a00c2407caed1fe61bdd92788f7a8eb27fcff969.tar.gz
Issue #20884: Don't assume in importlib.__init__ that __file__ is
defined.
-rw-r--r--Lib/importlib/__init__.py7
-rw-r--r--Misc/NEWS2
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index f6adc5cdcf..1bc99474f2 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -22,7 +22,12 @@ else:
# a second copy of the module.
_bootstrap.__name__ = 'importlib._bootstrap'
_bootstrap.__package__ = 'importlib'
- _bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py')
+ try:
+ _bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py')
+ except NameError:
+ # __file__ is not guaranteed to be defined, e.g. if this code gets
+ # frozen by a tool like cx_Freeze.
+ pass
sys.modules['importlib._bootstrap'] = _bootstrap
# To simplify imports in test code
diff --git a/Misc/NEWS b/Misc/NEWS
index 33e7092af1..ab25f1a8bc 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,8 @@ Core and Builtins
Library
-------
+- Issue #20884: Don't assume that __file__ is defined on importlib.__init__.
+
- Issue #20879: Delay the initialization of encoding and decoding tables for
base32, ascii85 and base85 codecs in the base64 module, and delay the
initialization of the unquote_to_bytes() table of the urllib.parse module, to