Guido van Rossum <gu...@python.org> added the comment:

Hum, there seems to be an actual bug here: even with PEP 563, the annotations 
for "complex targets" are evaluated. For example:

from __future__ import annotations
class C:
    x.y: z.w
    a: b.c

The relevant parts of the disassembly of the code for the class object are:

  3          10 LOAD_NAME                3 (x)
             12 POP_TOP
             14 LOAD_NAME                4 (z)
             16 LOAD_ATTR                5 (w)
             18 POP_TOP

  4          20 LOAD_CONST               1 ('b.c')
             22 LOAD_NAME                6 (__annotations__)
             24 LOAD_CONST               2 ('a')
             26 STORE_SUBSCR

So for x.y: z.w, not only do we evaluate x, we also evaluate z.w; whereas b.c 
is not evaluated (the stringified version is added as __annotations__['a']).

I think the "LOAD_NAME(x), POP_TOP" part is correct, but "LOAD_NAME(z), 
LOAD_ATTR(w), POP_TOP" should not be generated at all.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42737>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to