[Python-ideas] Importing orphaned bytecode files

Guido van Rossum guido at python.org
Wed Dec 9 04:30:25 CET 2009


On Tue, Dec 8, 2009 at 6:28 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Eric Smith <eric at trueblade.com> writes:
>
>> Ben Finney wrote:
>> > 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 agree with this in principle
>
> Thanks.
>
>> but I don't see how you're going to implement it. In order to actually
>> check this condition, aren't you going to have to compile the source
>> code anyway? If so, just skip the bytecode file. Although I guess you
>> could store a hash of the source in the compiled file, or other
>> similar optimizations.
>
> You seem to be seeing something I was careful not to write. The check
> is:
>
>   this source file would, if compiled, result in a bytecode file
>   replacing this one
>
> Nowhere there is there anything about the resulting bytecode files being
> equivalent. I'm limiting the check only to whether the resulting
> bytecode file would *replace* the existing bytecode file.
>
> This doesn't require knowing anything at all about the contents of the
> current bytecode file; indeed, my intention was to phrase it so that
> it's checked before bothering to open the existing bytecode file.
>
> Is there a better term for this? I'm not well-versed enough in the
> Python import internals to know.

If there was a corresponding source file, it would have been found
first -- and the bytecode file would be used *if* it matches the
source file (by comparing a timestamp in the bytecode file's header to
the actual mtime of the source file).

So I'm not sure what there is to do apart from *not* using "lone"
bytecode files. (The latter was actually added as a feature at some
point so I betcha it's easy to make it conditional on a flag.)

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list