Antoine Pietri <[email protected]> added the comment:
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
----------
nosy: +antoine.pietri
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue34961>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com