Skip to content

Conversation

@wangym5106
Copy link
Contributor

For example:

def test():
    c = 1

Decompiled result:

# uncompyle6 version 3.9.3.dev0
# Python bytecode version base 2.7 (62211)
# 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: /cwd/test.py
# Compiled at: 2025-11-21 19:12:13
def test():
    c = 1
    return


return

# okay decompiling .\test.pyc

This issue is caused by 4ac5564, will produce redundant return for every function in python 2.7.
This PR will fix it.

@wangym5106
Copy link
Contributor Author

wangym5106 commented Nov 23, 2025

Also, the same commit(4ac5564) caused this issue will also cause empty function/module/class decompile to return instead of pass for both python2 and python3:

class Test:
    pass

Decompiled:

class Test:
    return

I haven't figure out how to resolve this.

@rocky
Copy link
Owner

rocky commented Nov 23, 2025

@wangym5106 For the next week and a half, I'm out of town on vacation. I will look at this, though, when I get home.

@rocky
Copy link
Owner

rocky commented Nov 25, 2025

I just had a chance to look at. Allow me to give a high-level overview.

At the base level, the return None is redundant. Redundant isn't per se wrong, just unnecessary.

I've been a little sloppy here, and I guess my excuse is that there's so much other stuff that's wrong, that this has taken priority. And it's also taken me a while to try to organize the process to make sense so tht the code can scale easily.

The good part of the PR is that the changes here are done after scanning and parsing.

For things like this — what we have is correct but maybe not idiomatic — what is used is a "transformation rule"

See https://github.com/rocky/python-uncompyle6/blob/master/uncompyle6/semantics/transform.py for examples of transformation rules. This is also mentioned briefly in the BlackHat Asia talk.

@wangym5106
Copy link
Contributor Author

This issue and another issue (#521 , that's a real wrong) is both caused by same reason: different attr & pattr between python 2 and 3. So for a better fix for these issues, can we unify the attr & pattr across python versions?

@rocky
Copy link
Owner

rocky commented Nov 26, 2025

@wangym5106 want to try revising this as a transformation rule for n_return?

@wangym5106
Copy link
Contributor Author

I'd like to. But actually all L1250-L1270 is for removing redundant return, should be move to a transformation rule. For this specific issue, it's caused by redundant return is removed successfully in python3 but failed in python2.
So I think we can hold this issue, after attr & pattr issue resolved, then move this to transformation rule.

@wangym5106 wangym5106 mentioned this pull request Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants