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 antoine.pietri
Recipients antoine.pietri, anton.barkovsky, multun
Date 2018-10-12.14:33:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539354822.84.0.788709270274.issue34961@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-10-12 14:33:42antoine.pietrisetrecipients: + antoine.pietri, anton.barkovsky, multun
2018-10-12 14:33:42antoine.pietrisetmessageid: <1539354822.84.0.788709270274.issue34961@psf.upfronthosting.co.za>
2018-10-12 14:33:42antoine.pietrilinkissue34961 messages
2018-10-12 14:33:42antoine.pietricreate