Skip to content

Decompiled wrong result with simple if statements  #506

Description

@DzAvril

Description

I mocked a very simple code block with there if statements. The decompiled result if different from the original code.

How to Reproduce

The original python code.

def foo(a, b, c):
    if a:
        a = 1
    if b:
        b = 2
    if c:
        c = 3

Generate .pyc with following command.
python3 -m py_compile test_uncompy.py
The decompile with uncompy;e6.
uncompyle6 -o ./__pycache__ ./__pycache__/test_uncompy.cpython-36.pyc

The output code is :

# uncompyle6 version 3.9.3.dev0
# Python bytecode version base 3.6 (3379)
# Decompiled from: Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
# [GCC 8.4.0]
# Embedded file name: test_uncompy.py
# Compiled at: 2024-11-13 18:46:46
# Size of source mod 2**32: 89 bytes


def foo(a, b, c):
    if a:
        a = 1
    else:
        if b:
            b = 2
        if c:
            c = 3

If there were more than two if statements than the result is not correct. Please have a look at this issue, thanks very much.

Output Given

# uncompyle6 version 3.9.3.dev0
# Python bytecode version base 3.6 (3379)
# Decompiled from: Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
# [GCC 8.4.0]
# Embedded file name: test_uncompy.py
# Compiled at: 2024-11-13 18:46:46
# Size of source mod 2**32: 89 bytes


def foo(a, b, c):
    if a:
        a = 1
    else:
        if b:
            b = 2
        if c:
            c = 3

Expected behavior

# uncompyle6 version 3.9.3.dev0
# Python bytecode version base 3.6 (3379)
# Decompiled from: Python 3.6.9 (default, Mar 10 2023, 16:46:00) 
# [GCC 8.4.0]
# Embedded file name: test_uncompy.py
# Compiled at: 2024-11-13 18:46:46
# Size of source mod 2**32: 89 bytes


def foo(a, b, c):
    if a:
        a = 1
    if b:
        b = 2
    if c:
        c = 3

Environment

uncompyle6, version 3.9.3.dev0
pydisasm, version 6.1.0
python 3.6.13 |Anaconda, Inc.| (default, Jun  4 2021, 14:25:59)
6.5.0-14-generic #14~22.04.1-Ubuntu

Workarounds

Priority

Additional Context

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions