Redundant "else:"

Open
#486 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Run the supplied Python reproducer through uncompyle6 and compare the result with the reported output. Trace the decompiler’s handling of the loop and its else clause; done means the output no longer emits a redundant else while preserving the trailing time.sleep(0.5).

Written by the indexing model from the issue text.

Description

Control Flow Python 3.8 Volunteer wanted Works on decompyle3

Description

a redundant "else:" will be printed

How to Reproduce

import time

L = ["a", "s"]
def thread():
    for c in L:
        if c == 'a':
            print(c)
            break
    time.sleep(0.5)

Output Given

# uncompyle6 version 3.9.1.dev0
# Python bytecode version base 3.8.0 (3413)
# Decompiled from: Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
# Embedded file name: simple.py
# Compiled at: 2024-03-05 23:58:49
# Size of source mod 2**32: 145 bytes
import time
L = ["a", "s"]

def thread():
    for c in L:
        if c == "a":
            print(c)
            break
    else:
        time.sleep(0.5)

Expected behavior

def thread():
    for c in L:
        if c == "a":
            print(c)
            break
+    time.sleep(0.5)
-    else:
-        time.sleep(0.5)

Environment

  • Uncompyle6 version: output from uncompyle6 --version uncompyle6 3.9.1.dev0
  • xdis version: output from pydisasm --version pydisasm, version 6.1.0.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 (tags/v3.8.10:3d8993a, May 3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
  • OS and Version: Windows 11 (23H2)
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.