[Python-ideas] Add a cryptographic hash (e.g SHA1) of source toPython Compiled objects?

Brett Cannon brett at python.org
Fri Feb 6 19:34:38 CET 2009

On Thu, Feb 5, 2009 at 19:38,  <rocky at gnu.org> wrote:
> Brett Cannon writes:
>  > On Wed, Feb 4, 2009 at 02:18, Arnaud Delobelle <arnodel at googlemail.com> wrote:
>  > > 2009/2/4  <rocky at gnu.org>:
>  > >
>  > >> There's also the mtime that needs to be ignored mentioned in prior
>  > >> posts. And is there a table which converts a magic number version back
>  > >> into a string with the Python version number? Thanks.
>  > >
>  > > You can look at Python/import.c, near the top of the file.
>  >
>  > The other option to see how all of this works is importlib as found in
>  > the py3k branch. That's in pure Python so it's easier to follow.
>  >
>  > -Brett
>  >
> Sorry for the delayed response - I finally had a chance to check out the
> py3k code and look.
> Perhaps I'm missing something. Although there is some really cool,
> well-written and neat Python code there (and some of the private
> methods there seem to me like they should public and somewhere else,

Still working on exposing the API.

> perhaps in os or os.path),

Nothing in that module belongs in os.

> I don't see a table mapping magic numbers
> to a string containing a Python version as you would find when running
> "python -V" and that's what was kind of asked for.

Sorry, misread the email. Python/import.c is the right place then.

> As Arnaud mentioned, Python/import.c has this magic-number mapping in
> comments near the top of the file. Of course one could take those
> comments and turn it into a dictionary, but I was hoping Python had
> such a dictionary/function built in already since needs to be
> maintained along with changes to the magic number.

It actually doesn't need to be maintained. If the magic number doesn't
match from a .pyc then it needs to be regenerated, period. We do not
try to see if the magic number can be different yet compatible with
the running interpreter. And as for changing it, it is simply a
specific increment along with committing the file. The magic number
history is documented in that file "just in case".


More information about the Python-ideas mailing list