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

Brett Cannon brett at python.org
Thu Jun 14 16:58:55 CEST 2012


On Wed, Jun 13, 2012 at 10:47 PM, R. David Murray <rdmurray at bitdance.com>wrote:

> On Thu, 14 Jun 2012 11:48:08 +1000, Nick Coghlan <ncoghlan at gmail.com>
> wrote:
> > On Thu, Jun 14, 2012 at 6:06 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> > > On 6/13/2012 2:46 PM, Antoine Pitrou wrote:
> > >
> > >> Not only docstrings, but also asserts. I think running a pyo without
> -O
> > >> would be a bug.
> > >
> > > That cat is already out of the bag ;-)
> > > People are doing that now by renaming x.pyo to x.pyc.
> > > Brett claims that it is also easy to do in 3.3 with a custom importer.
> >
> > Right, but by resorting to either of those approaches, people are
> > clearly doing something that isn't formally supported by the core.
> > Yes, you can do it, and most of the time it will work out OK, but any
> > weird glitches that result are officially *not our problem*.
> >
> > The main reason this matters is that the "__debug__" flag is
> > *supposed* to be process global - if you check it in one place, the
>
> OK, the above are the two concrete reasons I have heard in this thread
> for continuing the current behavior:
>
>    1) we do not wish to support running from .pyo files without -O
>       being on, even if it currently happens to work
>
>    2) the __debug__ setting is supposed to be process-global
>
> Both of these are good reasons.  IMO the issue should be closed with a
> documentation fix, which could optionally include either or both of the
> above motivations.
>

Just for completeness, there is a third reason:

3) Would lead to an extra stat call per module when doing sourceless loads.

While minor, it could add up if you ship only .pyo files but never run with
-O.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120614/7411e790/attachment.html>


More information about the Python-Dev mailing list