Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Args not appearing in decompiled src when kwargs is specified explicitly (call_ex_kw) #227

Closed
x0ret opened this issue May 9, 2019 · 2 comments

Comments

@x0ret
Copy link
Collaborator

x0ret commented May 9, 2019

First of all, i should thank you for such an incredible efforts and educational project.

Description

Suppose the following code:

def func():
    return testobj.testmethod(c, test="A", **extra_args)

using uncompyle6 decompiles this to :

def func():
    return testobj.testmethod(test='A', **extra_args)

According to customize36.py this can be fixed with following patch:

diff --git a/uncompyle6/semantics/customize36.py b/uncompyle6/semantics/customize36.py
index 764a87e8..7e08c517 100644
--- a/uncompyle6/semantics/customize36.py
+++ b/uncompyle6/semantics/customize36.py
@@ -69,8 +69,8 @@ def customize_for_version36(self, version):
             '%c(%p)',
             (0, 'expr'), (1, 100)),
         'call_ex_kw' : (
-            '%c(%p)',
-            (0, 'expr'), (2, 100)),
+            '%c(*%c, %p)',
+            (0, 'expr'), (1, 'expr'), (2, 100)),

     })

How to Reproduce

Please use following commands:

$ cat test5.py
def func():
    return testobj.testmethod(c, test="A", **extra_args)
$ python -m compileall .
Listing '.'...
Compiling './test5.py'..
$ uncompyle6 __pycache__/test5.cpython-36.pyc
# uncompyle6 version 3.3.2
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.7 (default, Oct 22 2018, 11:32:17)
# [GCC 8.2.0]
# Embedded file name: ./test5.py
# Compiled at: 2019-05-09 15:23:19
# Size of source mod 2**32: 81 bytes


def func():
    return testobj.testmethod(test='A', **extra_args)
# okay decompiling __pycache__/test5.cpython-36.pyc

Expected behavior

decompilation like:

def func():
    return testobj.testmethod(*(c,), test='A', **extra_args)

Environment

  • Uncompyle6 version: master HEAD b57ca392
  • Python version: 3.6.7
  • OS and Version: Ubuntu bionic

Since i am new to this project if the above fix is accurate please let me know to propose a PR.

Thank you

@rocky rocky closed this as completed in e875b79 May 9, 2019
@rocky
Copy link
Owner

rocky commented May 9, 2019

Thanks for the patch. It has been applied with some slight modification, so you might look at that to see the difference. In the future, I do prefer PR's. That way everyone will know you were the one who not only noticed but also fixed this.

The main thing was to add a runnable test (when this is run under Python 3.6), that is not only decompiling the bytecode, but running the resulting Python to see that everything really works.

One other comment about the specific code. Although this fix is technically correct and matches more closely what the bytecode is doing, it is not all that idiomatic. With a little bit of extra work
we could have had:

return testobj.testmethod(c, test='A', **extra_args)

instead of

return testobj.testmethod(*(c,), test='A', **extra_args)

But that would mean writing a custom method for call_ex_kw_ done by creating a function called n_call_ex_kw().

On the other hand, what you propose is correct and what was there was wrong, so correct beats wrong.

Lastly, I'll admit that there are number of errors in uncompyle6 and it is not that hard to find them.

As a hobby, I work my way across another instead of doing, say, a crossword puzzle.

@x0ret
Copy link
Collaborator Author

x0ret commented May 9, 2019

Thank your for this comprehensive comment.
I implemented n_call_ex_kw in the following PR. Please feel free to adjust the PR as you wish.

However I'm not sure about LOAD_CONST in the commit. is this correct in that case?

Thank you

rocky added a commit that referenced this issue May 10, 2019
implements n_call_ex_kw as discussed in #227
@rocky rocky changed the title args not appearing in decompiled src when kwargs is specified explicitly (call_ex_kw) Args not appearing in decompiled src when kwargs is specified explicitly (call_ex_kw) May 19, 2019
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

No branches or pull requests

2 participants