[Python-Dev] #12982: Should -O be required to *read* .pyo files?

Ethan Furman ethan at stoneleaf.us
Wed Jun 13 20:41:56 CEST 2012


Toshio Kuratomi wrote:
> On Wed, Jun 13, 2012 at 01:58:10PM -0400, R. David Murray wrote:
>> OK, but you didn't answer the question :). If I understand correctly,
>> everything you said applies to *writing* the bytecode, not reading it.
>>>> So, is there any reason to not use the .pyo file (if that's all that is
>> around) when -O is not specified?
>>>> The only technical reason I can see why -O should be required for a .pyo
>> file to be used (*if* it is the only thing around) is if it won't *run*
>> without the -O switch. Is there any expectation that that will ever be
>> the case?
>>> Yes. For instance, if I create a .pyo with -OO it wouldn't have docstrings.
> Another piece of code can legally import that and try to use the docstring
> for something. This would fail if only the .pyo was present.

Why should it fail? -OO causes docstring access to return None, just as 
if a docstring had not been specified in the first place. Any decent 
code will be checking for an undefined docstring -- after all, they are 
not rare.
~Ethan~


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /