Message165596
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. |
|
Date |
User |
Action |
Args |
2012-07-16 12:52:36 | meador.inge | set | recipients:
+ meador.inge |
2012-07-16 12:52:36 | meador.inge | set | messageid: <1342443156.65.0.45067374653.issue15368@psf.upfronthosting.co.za> |
2012-07-16 12:52:36 | meador.inge | link | issue15368 messages |
2012-07-16 12:52:35 | meador.inge | create | |
|