rocky / python-uncompyle6

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

missing parentheses of a lambda call #350

Closed hzqmwne closed 3 years ago

hzqmwne commented 3 years ago

Description

missing parentheses of a lambda call

How to Reproduce

This is the source code:

A = (lambda x : x)(print)

then compile it with:

python3 -m compileall -b test.py

and decompile it

uncompyle6 test.pyc >test_dec.py

the output is:

A = lambda x: x(print)

the decompiled code is obviously error, that the parentheses are missing

Expected behavior

expected decompiled code is:

A = (lambda x : x)(print)

Environment

this bug can be repeated in such environments:

Ubuntu 20.04
Python 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0] on linux
uncompyle6 3.7.4 from pip

or

Ubuntu 18.04
Python 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]
uncompyle6 3.7.4 from pip

Additional Environment or Context

This bug also exists in decompyle3 3.3.2

rocky commented 3 years ago

Fixed now in decompyle3 in commit https://github.com/rocky/python-decompile3/commit/8c7e583c404836b4c5c37f19f9c290d968774206.

I leave as an exercise for reader adapting this fix for this repository. Note though that in this code base we don't generally use x if condition else y since we do try to keep compatible with older Pythons.

The bug goes back all the way to Python 2.2 if not before (which is why I didn't ask about the version number earlier).

rocky commented 3 years ago

Fixed by #352