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 large dictionary displays used as comprehension elements. The code below currently confuses dictionary construction with the enclosing comprehension's own key/value operation and produces invalid source:
A large dictionary literal uses
MAP_ADD 1while being built as a list-comprehension element. The parser currently interprets any active-comprehension MAP_ADD as the enclosing comprehension's own key/value operation, so dictionary fields can overwrite its element bookkeeping.The fix makes the statement parser route argument-one collection operations to ordinary collection construction. The separate comprehension/generator walker also extends its current dictionary for
MAP_ADD 1, rather than recording an enclosing key. The same display therefore remains a dictionary when used as a generator-expression element,({...} for row in rows). Ordinary dictionary comprehensions, such as{row: row + 1 for row in rows}, keep their existing key/value handling.CPython begins emitting this large-display layout in 3.10:
compiler_subdictin 3.10 usesMAP_ADD 1when the display exceeds its stack-use guideline; 3.9's compiler does not use that layout. Both guards therefore start at 3.10, including the separate-code-object comprehensions used before 3.12.