andrews4s / unpyc37

Decompiler for Python 3.7 (forked from https://github.com/figment/unpyc3)
GNU General Public License v3.0
57 stars 19 forks source link

list comprehension with if/else #8

Open rocky opened 5 years ago

rocky commented 5 years ago

decompiling compiled:

def lc(fields):
    flds = [f for f in fields if (f.compare if f.hash is None else f.hash)]

gives:

$ python unpyc37/unpyc3.py /tmp/cbug2-3.7.pyc
Traceback (most recent call last):
  File "unpyc37/unpyc3.py", line 2907, in <module>
    print(decompile(sys.argv[1]))
  File "unpyc37/unpyc3.py", line 1505, in __str__
    self.display(istr)
  File "unpyc37/unpyc3.py", line 1511, in display
    stmt.display(indent)
  File "unpyc37/unpyc3.py", line 1335, in display
    self.display_undecorated(indent)
  File "unpyc37/unpyc3.py", line 1361, in display_undecorated
    self.code.get_suite().display(indent + 1)
  File "unpyc37/unpyc3.py", line 1511, in display
    stmt.display(indent)
  File "unpyc37/unpyc3.py", line 1164, in display
    indent.write(" = ".join(map(str, self.chain)))
  File "unpyc37/unpyc3.py", line 1028, in __str__
    return self.pattern.format(suite.gen_display())
  File "unpyc37/unpyc3.py", line 1518, in gen_display
    return self[0].gen_display(seq)
  File "unpyc37/unpyc3.py", line 1314, in gen_display
    return self.body.gen_display(seq + (s,))
  File "unpyc37/unpyc3.py", line 1517, in gen_display
    raise Exception('There should only be one statement in a generator.')
Exception: There should only be one statement in a generator.
rocky commented 5 years ago

Should also add that self here is:

'if f.hash is None:\n if f.compare:\n f\nelif f.hash:\n f\nf'