This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Peter Ebden
Recipients Peter Ebden
Date 2018-09-18.13:53:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
We've found that the following code produces non-deterministic bytecode,
even post PEP-552:

def test(x):
    if x in {'ONE', 'TWO', 'THREE'}:

It's not too hard to test it:

$ python3.7 -m compileall --invalidation-mode=unchecked-hash
Compiling ''...
$ sha1sum __pycache__/test.cpython-37.pyc
61e5682ca95e8707b4ef2a79f64566664dafd800  __pycache__/test.cpython-37.pyc
$ rm __pycache__/test.cpython-37.pyc
$ python3.7 -m compileall --invalidation-mode=unchecked-hash
Compiling ''...
$ sha1sum __pycache__/test.cpython-37.pyc
222a06621b491879e5317b34e9dd715bacd89b7d  __pycache__/test.cpython-37.pyc

It looks like the peephole optimiser is converting the LOAD_CONST instructions
for the set into a single LOAD_CONST for a frozenset which then serialises in
nondeterministic order. One can hence work around it by setting PYTHONHASHSEED
to a known value.

I'm happy to help out with this if needed, although I don't have a lot of
familiarity with the relevant code.
Date User Action Args
2018-09-18 13:53:47Peter Ebdensetrecipients: + Peter Ebden
2018-09-18 13:53:47Peter Ebdensetmessageid: <>
2018-09-18 13:53:47Peter Ebdenlinkissue34722 messages
2018-09-18 13:53:47Peter Ebdencreate