[Python-Dev] PEP 552: deterministic pycs

Nick Coghlan ncoghlan at gmail.com
Fri Sep 8 10:49:46 EDT 2017


On 8 September 2017 at 03:04, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Thu, 7 Sep 2017 18:47:20 -0700
> Nick Coghlan <ncoghlan at gmail.com> wrote:
>> However, I do wonder whether we could encode *all* the mode settings
>> into the magic number, such that we did something like reserving the
>> top 3 bits for format flags:
>>
>> * number & 0x1FFF -> the traditional magic number
>> * number & 0x8000 -> timestamp or hash?
>> * number & 0x4000 -> checked or not?
>> * number & 0x2000 -> reserved for future format changes
>
> I'd rather a single magic number and a separate bitfield that tells
> what the header encodes exactly.  We don't *have* to fight for a tiny
> size reduction of pyc files.

One of Benjamin's goals was for the existing timestamp-based pyc
format to remain completely unchanged, so we need some kind of marker
in the magic number to indicate whether the file is using the new
format or nor.

I'd also be fine with using a single bit for that, such that the only
bitmasking needed was:

* number & 0x8000 -> legacy format or new format?
* number & 0x7FFF -> the magic number itself

And any further flags would go in a separate field.

That's essentially what PEP 552 already suggests, the only adjustment
is the idea of specifically using the high order bit in the magic
number field to indicate the pyc format in use rather than leaving the
explanation of how the two magic numbers will differ unspecified.

Cheers,
Nick.

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


More information about the Python-Dev mailing list