List comprehensions inside of a lambda print only `[`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the poc.py reproduction and run py_compile on Python 3.8, then decompile the resulting .pyc with uncompyle6. Compare the lambda case with the working def case and trace how the list-comprehension bytecode is handled; done means the complete comprehension is emitted for the lambda example.
Written by the indexing model from the issue text.
Description
Description
List comprehensions inside of a lambda print a single [ bracket instead of the list comprehension, resulting in invalid syntax.
How to Reproduce
The following is a simple list comprehension in a lambda function:
# fmt:off
a = lambda n: [i + 1 for i in range(n)]
Stored in a file called poc.py, it can be compiled into a .pyc file with the following commands:
python3 -c 'import py_compile; print(py_compile.compile("poc.py"))'
uncompyle6 __pycache__/poc.cpython-38.pyc
It decompiles to the following code on the latest 3.9.1 version:
# Size of source mod 2**32: 50 bytes
a = lambda n: [
# okay decompiling __pycache__/poc.cpython-38.pyc
This happens while a regular function using def containing a list comprehension does work perfectly:
def a(n):
return [i + 1 for i in range(n)]
Expected behavior
Write the whole list comprehension just like a function using def would. This would be the expected output for the example above:
a = lambda n: [i + 1 for i in range(n)]
Environment
$ uncompyle6 --version
uncompyle6, version 3.9.1
$ pydisasm --version
pydisasm, version 6.1.0
$ python3 -c "import sys; print(sys.version)"
3.8.10 (default, Nov 22 2023, 10:22:35)
[GCC 9.4.0]
$ cat /etc/issue
Ubuntu 20.04.6 LTS
Workarounds
Ignore the missing list comprehension code in the output, because it continues to print the code after it. This won't make the code inside the list comprehension visible though.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 464
- Avg merge
- 6d 12h
- Merged PRs (30d)
- 2
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rocky/python-uncompyle6
-
Difficulty 3/5 1-2 days Newbie friendliness 65/100
rocky/python-uncompyle6#527 · 1 comment ·
-
Works on decompyle3
Difficulty 4/5 3-5 days Newbie friendliness 35/100
rocky/python-uncompyle6#506 · 1 comment ·
-
Redundant "else:"OpenControl Flow Python 3.8 Volunteer wanted Works on decompyle3
Difficulty 4/5 3-5 days Newbie friendliness 45/100
rocky/python-uncompyle6#486 ·
-
Missing "While True"OpenControl Flow Python 3.8 Volunteer wanted Works on decompyle3
Difficulty 4/5 3-5 days Newbie friendliness 45/100
rocky/python-uncompyle6#485 · 4 comments ·
-
Duplicate Python 3.9+
Difficulty 5/5 Over a week Newbie friendliness 25/100
rocky/python-uncompyle6#484 · 9 reactions ·
All issues in rocky/python-uncompyle6
Similar issues
-
comp/tools duplicate P2 sweeper:risk-compatibility tool/mcp type/bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
NousResearch/hermes-agent#132042 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
deepset-ai/haystack#13092 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
EverMind-AI/Raven#845 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AstrBotDevs/AstrBot#10340 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
BasedHardware/omi#20401 · 1 comment ·
Maintainers usually reply within 1 day