[Python-Dev] #12982: Should -O be required to *read* .pyo files?
Ethan Furman
ethan at stoneleaf.us
Thu Jun 14 05:39:04 CEST 2012
Steven D'Aprano wrote:
> On Wed, Jun 13, 2012 at 03:13:54PM -0400, R. David Murray wrote:
>
>> Again, a program that depends on asserts is buggy.
>>
>> As Ethan pointed out we are asking about the case where someone is
>> *deliberately* setting the .pyo file up to be run as the "normal"
>> case.
>
> You can't be sure that the .pyo file is there due to *deliberate*
> choice. It may be accidental. Perhaps the end user has ignorantly
> deleted the .pyc file, but failed to delete the .pyo file. Perhaps the
> developer has merely made a mistake.
You can't just delete the .pyc file to get the .pyo file to run;
remember in 3.x compiled files are kept in a __pycache__ folder, and if
there is no .py file the compiled files are ignored (correct me if I'm
wrong), so to get the either the .pyc file /or/ the .pyo file to run
/without/ a .py file, you have to physically move the compiled file to
where the source file should be. It could still be accidental, but it's
far less likely to be.
> Under current behaviour, deleting the .pyc file shouldn't matter:
>
> - if the source file is available, that will be used
> - if not, a clear error is raised
>
> Under the proposed change:
>
> - if the source file is *newer* than the .pyo file, it will be used
> - but if it is missing or older, the .pyo file is used
Again, not in 3.x.
~Ethan~
More information about the Python-Dev
mailing list