Skip to content

Comprehension inlining: Bug if comprehension contains a lambda #104357

Closed
@JelleZijlstra

Description

@JelleZijlstra

Code sample:

def outer(x):
    return [lambda: x for x in range(x)]

print([f() for f in outer(2)])

On 3.11, this produces [1, 1] as expected.

But on current main, I get:

>>> [f() for f in outer(2)]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in outer
TypeError: 'cell' object cannot be interpreted as an integer

Almost certainly due to PEP 709 / #101441, cc @carljm.

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions