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

rocky at gnu.org rocky at gnu.org
Thu Feb 5 23:40:34 CET 2009

Terry Reedy writes:
 > Instead of comparing marshal strings, custom compare the code objects, 
 > ignoring .co_filename.
 > tjr

Alas, I suspect going down this path will lead to plugging more and
more leaks. It is not just co_filename that might need ignoring,
possibly artifacts from __file__ as well.

When I run this Python program:

  import marshal
  print marshal.dumps(compile(open(__file__).read(), __file__, 'exec'))

which I store in "/tmp/foo.py", and I look at the output, I see the
string "/tmp/foo.py".  No doubt this comes from whereever the value of
__file__ is stored which seems computed at compile time. So one would
probably need to ignore the values of __file__ variables, where ever
that is stored.

That said, if someone can write such a program I'd appreciate it.

More information about the Python-ideas mailing list