Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I am opening this PR to fix nested comprehension reconstruction when an iterator-producing call takes an empty container as a default argument. The code below currently loses its comprehension structure and is reconstructed correctly with this change:
An empty list or map preceding an iterator need not be a new comprehension's result container: it may already have been consumed as a method argument. The prologue detector currently accepts an earlier empty
BUILD_LIST,BUILD_SETorBUILD_MAPwithout distinguishing those uses. The fix requires the modern accumulator's immediateSWAP 2placement before treating it as a new comprehension level.The same distinction matters for set and dictionary results:
{field for row in rows for field in row.get("values", {})} {field: len(field) for row in rows for field in row.get("values", {})}Separately nested comprehensions must keep their own accumulator, including:
Direct
row["values"], a call without a default, and a tuple default retain their existing interpretation. The surrounding function's savedrowandfieldbindings must also survive comprehension cleanup.This accumulator layout begins with comprehension inlining in Python 3.12. The additional
SWAP 2requirement therefore applies from 3.12, preserving the older prologue handling.