@@ -411,25 +411,21 @@ def _call_with_frames_removed(f, *args, **kwds):
411411
412412DEBUG_BYTECODE_SUFFIXES = ['.pyc' ]
413413OPTIMIZED_BYTECODE_SUFFIXES = ['.pyo' ]
414- if __debug__ :
415- BYTECODE_SUFFIXES = DEBUG_BYTECODE_SUFFIXES
416- else :
417- BYTECODE_SUFFIXES = OPTIMIZED_BYTECODE_SUFFIXES
418414
419415def 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
0 commit comments