Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

List comprehensions inside of a lambda print only `[`

Open
#492 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

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

Python 3.8 Volunteer wanted Works on decompyle3

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rocky/python-uncompyle6

All issues in rocky/python-uncompyle6

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.