GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Comprehension inlining: Bug if comprehension contains a lambda · Issue #104357 · python/cpython

Comprehension inlining: Bug if comprehension contains a lambda #104357

New issue
Copy link
New issue
Copy link
Closed
#104368
Closed
Comprehension inlining: Bug if comprehension contains a lambda#104357
#104368
Copy link
Assignees
carljm
Labels
release-blockertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@JelleZijlstra
JelleZijlstra
opened on May 10, 2023
Issue body actions

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

  • gh-104357: fix inlined comprehensions that close over iteration var #104368
Reacted by sunmy2019 and Carl Meyer

Activity

  1. JelleZijlstra
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    release-blocker
    on May 10, 2023
  2. ezio-melotti
    added this to Release and Deferred blockers 🚫on May 10, 2023
  3. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on May 10, 2023
  4. carljm
    self-assigned this
    on May 10, 2023
  5. carljm commented on May 10, 2023

    @carljm
    carljm
    on May 10, 2023
    Member
    More actions

    Thanks for finding this case! I had tests for similar cases with lambda inside the comprehension using the same name as non-cell outside the comprehension, but they were all of the form:

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

    The key factor in your example is that there is no store to x in the outer scope, because it is an argument.

  6. carljm
    added a commit that references this issue on May 10, 2023

    pythongh-104357: fix inlined comprehensions with cells

    a9c5a4f
  7. JelleZijlstra
    closed this as completedin #104368on May 11, 2023
  8. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on May 11, 2023
  9. JelleZijlstra
    added a commit that references this issue on May 11, 2023

    gh-104357: fix inlined comprehensions that close over iteration var (#…

    fcd5fb4
  10. carljm
    added 2 commits that reference this issue on May 11, 2023

    Merge branch 'main' into supermon

    19b3d9e

    Merge branch 'main' into fixloadsuperspec

    4456dd6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @carljm
    carljm

Labels

release-blockertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Release and Deferred blockers 🚫
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.