[Python-Dev] PEP 3147: PYC Repository Directories

Nick Coghlan ncoghlan at gmail.com
Sun Feb 7 07:15:39 CET 2010


exarkun at twistedmatrix.com wrote:
> On 08:21 pm, barry at python.org wrote:
>> On Feb 03, 2010, at 01:17 PM, Guido van Rossum wrote:
>>> Can you clarify? In Python 3, __file__ always points to the source.
>>> Clearly that is the way of the future. For 99.99% of uses of __file__,
>>> if it suddenly never pointed to a .pyc file any more (even if one
>>> existed) that would be just fine. So what's this talk of switching to
>>> __source__?
>>
>> Upon further reflection, I agree.  __file__ also points to the source in
>> Python 2.7.  Do we need an attribute to point to the compiled bytecode
>> file?
> 
> What if, instead of trying to annotate the module object with this
> assortment of metadata - metadata which depends on lots of things, and
> can vary from interpreter to interpreter, and even from module to module
> (depending on how it was loaded) - we just stuck with the __loader__
> annotation, and encouraged/allowed/facilitated the use of the loader
> object to learn all of this extra information?

Trickier than it sounds. In the case of answering the question "was this
module loaded from bytecode or not?", the loader will need somewhere to
store the answer for each file.

The easiest per-module store is the module's own global namespace - the
loader's own attribute namespace isn't appropriate, since one loader may
handle multiple modules.

The filesystem can't be used as a reference because even when the file
is loaded from source, the bytecode file will usually be created as a
side effect.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list