Double return is printed

Open
#459 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start with the minimal Python example and the bytecode_3.8/00_double_return.pyc case generated using add-test.py. Reproduce the decompilation on Python 3.8 and inspect the relevant return-handling path to find why return and return None are emitted together. Done means the output contains only return and the regression case confirms the expected decompilation.

Written by the indexing model from the issue text.

Description

Bug Python 3.8 Volunteer wanted Works on decompyle3

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

  • Uncompyle6 version: output from uncompyle6 --version uncompyle6 3.9.1.dev0
  • Python version for the version of Python the byte-compiled the file: python -c "import sys; print(sys.version)" where python is the correct CPython or PyPy binary.
    3.8.10 (default, Mar 13 2023, 10:26:41)
    [GCC 9.4.0]
  • OS and Version: Linux codespaces-6db051 5.15.0-1038-azure #45-Ubuntu SMP Mon Apr 24 15:40:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Workarounds

Remove the second run by hand

Priority

I found it while trying to reduce another bug

Additional Context

N/A

Dominant language
Python
Stars
4.3k
Forks
463
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rocky/python-uncompyle6

All issues in rocky/python-uncompyle6

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.