Message327588
Tracking down the issue a bit further:
a = 10
def main():
a = 42
class wtf():
print(a)
class wtf2():
print(a)
a = 2
main()
prints:
42
10
It seems that when there is an assignation in the class body, prior usages of the variables in the class body are done by loading the variable using LOAD_NAME instead of LOAD_CLASSDEREF:
Disassembly of <code object wtf at 0x7fa1b8b01390, file "lolmul.py", line 7>:
[...]
8 8 LOAD_NAME 3 (print)
10 LOAD_CLASSDEREF 0 (a)
12 CALL_FUNCTION 1
14 POP_TOP
16 LOAD_CONST 1 (None)
18 RETURN_VALUE
Disassembly of <code object wtf2 at 0x7fa1b8b018a0, file "lolmul.py", line 10>:
[...]
11 8 LOAD_NAME 3 (print)
10 LOAD_NAME 4 (a)
12 CALL_FUNCTION 1
14 POP_TOP
12 16 LOAD_CONST 1 (2)
18 STORE_NAME 4 (a)
20 LOAD_CONST 2 (None)
22 RETURN_VALUE |
|
Date |
User |
Action |
Args |
2018-10-12 14:33:42 | antoine.pietri | set | recipients:
+ antoine.pietri, anton.barkovsky, multun |
2018-10-12 14:33:42 | antoine.pietri | set | messageid: <1539354822.84.0.788709270274.issue34961@psf.upfronthosting.co.za> |
2018-10-12 14:33:42 | antoine.pietri | link | issue34961 messages |
2018-10-12 14:33:42 | antoine.pietri | create | |
|