pycdc icon indicating copy to clipboard operation
pycdc copied to clipboard

python 3.0 chained expressions

Open rocky opened this issue 7 years ago • 1 comments

if [] == r == w == e:
    r = [1]
assert r == [1]

compiled and decompiled comes out as:

r = []
w = []
e = []
if [] == r and r == w:
    pass
w == e
if 1:
    r = [
        1]

if not r == [
    1]:
    raise AssertionError

rocky avatar Jun 23 '18 11:06 rocky

I'd like to have a look at this :) I opened #184 while doing this, just to address the empty unpack.

EDIT: I misread the issue, I thought this was for chained assignments 🤦 I will keep working on supporting chained assignments anyway e.g. a = b = c since I've made some progress with it. Will raise another issue if need be.

For this issue, here is some Py 3.7 bytecode for anyone who wants to have a quick look:

Compile/decompile:
a == b == c

[Disassembly]
        0       LOAD_NAME               0: a
        2       LOAD_NAME               1: b
        4       DUP_TOP
        6       ROT_THREE
        8       COMPARE_OP              2 (==)
        10      JUMP_IF_FALSE_OR_POP    18
        12      LOAD_NAME               2: c
        14      COMPARE_OP              2 (==)
        16      JUMP_FORWARD            4 (to 22)
        18      ROT_TWO
        20      POP_TOP
        22      POP_TOP
        24      LOAD_CONST              0: None
        26      RETURN_VALUE

if a == b:
    pass
b == c
1

Aralox avatar Oct 23 '20 00:10 Aralox