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 meador.inge
Recipients meador.inge
Date 2012-07-16.12:52:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1342443156.65.0.45067374653.issue15368@psf.upfronthosting.co.za>
In-reply-to
Content
Consider this small example (you might have to run sample program multiple 
times to see a difference):

$ cat dis-closure.py
import dis

def adder(a, b):
    def add():
        return a + b
    return add

print(dis.dis(adder(1, 2).__code__))

$  ./python.exe dis-closure.py
  5           0 LOAD_DEREF               0 (a) 
              3 LOAD_DEREF               1 (b) 
              6 BINARY_ADD           
              7 RETURN_VALUE         
None
$  ./python.exe dis-closure.py
  5           0 LOAD_DEREF               1 (a) 
              3 LOAD_DEREF               0 (b) 
              6 BINARY_ADD           
              7 RETURN_VALUE         
None

The order of 'co_cellvars' and 'co_freevars' can be different from compile to 
compile, thus the bytecode can be different from compile to compile.

This is due to the fact that these variable sets are managed with hashes and
the ordering may come out different when the names in the hashes are given
indexes (via 'dictbytype' in 'compile.c').

I am not sure if these are the only areas that causes bytecode generation
to be non-deterministic.  I found this behavior surprising.
History
Date User Action Args
2012-07-16 12:52:36meador.ingesetrecipients: + meador.inge
2012-07-16 12:52:36meador.ingesetmessageid: <1342443156.65.0.45067374653.issue15368@psf.upfronthosting.co.za>
2012-07-16 12:52:36meador.ingelinkissue15368 messages
2012-07-16 12:52:35meador.ingecreate