]> granicus.if.org Git - python/commitdiff
Issue #20884: Don't assume in importlib.__init__ that __file__ is
authorBrett Cannon <brett@python.org>
Fri, 21 Mar 2014 14:58:33 +0000 (10:58 -0400)
committerBrett Cannon <brett@python.org>
Fri, 21 Mar 2014 14:58:33 +0000 (10:58 -0400)
defined.

Lib/importlib/__init__.py
Misc/NEWS

index f6adc5cdcf6fa708301cbc158000f7f3bb69380d..1bc99474f2ac4782ce813119b00ba741b81065cc 100644 (file)
@@ -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
index 33e7092af1721ab02c7a1a9871c09ef0a426b920..ab25f1a8bc1e8a9dfe7fe210c231a5c7f38c308d 100644 (file)
--- 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