rocky / python-uncompyle6

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

Redundant "else:" #486

Open hikali8 opened 6 months ago

hikali8 commented 6 months ago

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