
Kristján Valur Jónsson <kristjan@ccpgames.com> writes:
Repeatedly we run into trouble because of stray .pyo (and/or .pyc) files. This can happen for a variety of reasons, but most often it occurs when .py files are being removed, or moved in the hierarchy. The problem is that the application will happily load and import an orphaned .pyo file, even though the .py file has gone or moved.
Yes, I think Python users would benefit from having the above behaviour be opt-in. I suggest: * A new attribute ‘sys.import_orphaned_bytecode’. If set ‘True’, the interpreter follows the current behaviour. If ‘False’, any bytecode file satisfies an import only if it has a corresponding source file (where “corresponding” means “this source file would, if compiled, result in a bytecode file replacing this one”). I suggest this attribute should be implemented as ‘True’ by default (to match current behaviour), then switched to ‘False’ by default as soon as feasible. * The ‘PYTHONIMPORTORPHANEDBYTECODE’ environment variable, when set, causes the interpreter to set the above option ‘True’. * The ‘-b’ option to the interpreter command-line sets the above option ‘True’. -- \ “I have yet to see any problem, however complicated, which, | `\ when you looked at it in the right way, did not become still | _o__) more complicated.” —Paul Anderson | Ben Finney