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

chained comparisons #5

Open rocky opened 5 years ago

rocky commented 5 years ago

This program:


def chained_compare_b(a, obj):
    if a:
        if -0x80000000 <= obj <= 0x7fffffff:
            return 5

chained_compare_b(True, 0x0)

when compiled and decompiled with unpyc37 gives:

Traceback (most recent call last):
  File "unpyc37/unpyc3.py", line 2899, 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 433, in get_suite
    dec.run()
  File "unpyc37/unpyc3.py", line 1594, in run
    new_addr = method(*args)
  File "unpyc37/unpyc3.py", line 2620, in POP_JUMP_IF_FALSE
    return self.POP_JUMP_IF(addr, target, truthiness=False)
  File "unpyc37/unpyc3.py", line 2447, in POP_JUMP_IF
    c = c.chain(cond)
AttributeError: 'PyName' object has no attribute 'chain'
rocky commented 5 years ago

Similar is:

digit = 1
if isinstance(digit, int) and 0 <= digit <= 9:
    pass