Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a00c240

Browse files
committed
Issue #20884: Don't assume in importlib.__init__ that __file__ is
defined.
1 parent 373f0a9 commit a00c240

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/importlib/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
# a second copy of the module.
2323
_bootstrap.__name__ = 'importlib._bootstrap'
2424
_bootstrap.__package__ = 'importlib'
25-
_bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py')
25+
try:
26+
_bootstrap.__file__ = __file__.replace('__init__.py', '_bootstrap.py')
27+
except NameError:
28+
# __file__ is not guaranteed to be defined, e.g. if this code gets
29+
# frozen by a tool like cx_Freeze.
30+
pass
2631
sys.modules['importlib._bootstrap'] = _bootstrap
2732

2833
# To simplify imports in test code

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Core and Builtins
2121
Library
2222
-------
2323

24+
- Issue #20884: Don't assume that __file__ is defined on importlib.__init__.
25+
2426
- Issue #20879: Delay the initialization of encoding and decoding tables for
2527
base32, ascii85 and base85 codecs in the base64 module, and delay the
2628
initialization of the unquote_to_bytes() table of the urllib.parse module, to

0 commit comments

Comments
 (0)