rocky / python-uncompyle6

A cross-version Python bytecode decompiler
GNU General Public License v3.0
3.74k stars 408 forks source link

Double return is printed #459

Open Et7f3 opened 1 year ago

Et7f3 commented 1 year ago

Description

double return get printed

How to Reproduce

def main():
  if input() == 0:
    print("0")
    return
  if input() == 1:
    print("1")
  else:
    printf("other")

https://github.com/rocky/python-uncompyle6/pull/458

I used add-test.py with python3.8 with the latest commit on the respective branch

Output Given

# uncompyle6 version 3.9.1.dev0
# Python bytecode version base 3.8.0 (3413)
# Decompiled from: Python 3.8.10 (default, Mar 13 2023, 10:26:41) 
# [GCC 9.4.0]
# Embedded file name: 00_double_return.py
# Compiled at: 2023-05-31 12:07:25
# Size of source mod 2**32: 118 bytes

def main():
    if input() == 0:
        print('0')
        return         return None
    elif input() == 1:
        print('1')
    else:
        printf('other')
# okay decompiling bytecode_3.8/00_double_return.pyc

Expected behavior

def main():
    if input() == 0:
        print('0')
+        return
-        return         return None
    elif input() == 1:
        print('1')
    else:
        printf('other')

Environment

Workarounds

Remove the second run by hand

Priority

I found it while trying to reduce another bug

Additional Context

N/A

rocky commented 1 year ago

This does not happen when decompyle3 is used. The obvious fix is to run both with the -gT options and make the grammars, tree, and semantic print actions align.

Et7f3 commented 1 year ago

While reducing a bug I found 2 others bugs (one that work on decompyle3 and not the second). Do you want I open 2 issues or something else ?

Link to repro (python 3.8):

Can I open draft PR like this issue ?

The priority of these bug is low because the result is pretty good and I can fix those occurrence by hand. Awesome works (hope my tests help you)

rocky commented 1 year ago

Open an issue for every problem - so two (or more) issues please. That way we can track each individually, tag each individually and so on.

PRs are for fixes; the are not a different way of reporting problems. You can attach bytecode and source code in issues.

I can fix those occurrence by hand.

And so as in this issue, that is a "workaround". That's why I have a section for this.

There are way more bugs than there are fixers of bugs. (That in fact is true for every Python decompiler that I am aware of). So feel free and try to fix the problems you report.