Skip to content

PEP 709, for the third and (hopefully) final time #192

@carljm

Description

@carljm

In light of the SC feedback that the change to class-scope name visibility in comprehensions discussed in https://discuss.python.org/t/pep-709-one-behavior-change-that-was-missed-in-the-pep/26691 is not acceptable for 3.12, @JelleZijlstra and I have been exploring options B and C as outlined in that post for keeping the optimization with the originally-approved semantics, and no additional behavior changes.

Jelle has a PR which preserves inlining of all list/dict/set comprehensions, while also preserving the previous scoping rules for names in class-scope comprehensions, so it exactly implements the originally-approved semantics of PEP 709. It turns out to be a pretty simple change after all: python/cpython#104528.

I checked with @Yhg1s as 3.12 release manager, and he is OK with moving ahead with Jelle's PR for 3.12.

But he asked me to also check here to see if anyone on the SC has a strong preference for the alternative fix, which is to disable inlining altogether in module and class scopes, where it is unlikely to be performance sensitive. I also have a PR up for that: python/cpython#104519. Relative to Jelle's PR, this approach keeps the compiler a bit simpler, but it means that the subtle behavior differences discussed in PEP 709 (regarding tracebacks and locals()) would be different for function-scoped comprehensions than for class/module-scoped ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions