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

Skip to content

Commit feaa54f

Browse files
committed
don't depend on __debug__ because it's baked in at freeze time (issue #16046)
1 parent d79ac0f commit feaa54f

3 files changed

Lines changed: 4241 additions & 4229 deletions

File tree

Lib/importlib/_bootstrap.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,25 +411,21 @@ def _call_with_frames_removed(f, *args, **kwds):
411411

412412
DEBUG_BYTECODE_SUFFIXES = ['.pyc']
413413
OPTIMIZED_BYTECODE_SUFFIXES = ['.pyo']
414-
if __debug__:
415-
BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
416-
else:
417-
BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
418414

419415
def cache_from_source(path, debug_override=None):
420416
"""Given the path to a .py file, return the path to its .pyc/.pyo file.
421417
422418
The .py file does not need to exist; this simply returns the path to the
423419
.pyc/.pyo file calculated as if the .py file were imported. The extension
424-
will be .pyc unless __debug__ is not defined, then it will be .pyo.
420+
will be .pyc unless sys.flags.optimize is non-zero, then it will be .pyo.
425421
426422
If debug_override is not None, then it must be a boolean and is taken as
427-
the value of __debug__ instead.
423+
the value of bool(sys.flags.optimize) instead.
428424
429425
If sys.implementation.cache_tag is None then NotImplementedError is raised.
430426
431427
"""
432-
debug = __debug__ if debug_override is None else debug_override
428+
debug = not sys.flags.optimize if debug_override is None else debug_override
433429
if debug:
434430
suffixes = DEBUG_BYTECODE_SUFFIXES
435431
else:
@@ -1688,10 +1684,15 @@ def _setup(sys_module, _imp_module):
16881684
modules, those two modules must be explicitly passed in.
16891685
16901686
"""
1691-
global _imp, sys
1687+
global _imp, sys, BYTECODE_SUFFIXES
16921688
_imp = _imp_module
16931689
sys = sys_module
16941690

1691+
if sys.flags.optimize:
1692+
BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
1693+
else:
1694+
BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
1695+
16951696
for module in (_imp, sys):
16961697
if not hasattr(module, '__loader__'):
16971698
module.__loader__ = BuiltinImporter

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ What's New in Python 3.3.1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #16046: Fix loading sourceless legacy pyos.
14+
1315
- Issue #15379: Fix passing of non-BMP characters as integers for the charmap
1416
decoder (already working as unicode strings). Patch by Serhiy Storchaka.
1517

0 commit comments

Comments
 (0)