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 preserve
and/orvalues inside comprehension elements. The code below currently turns the fallback expression into a filter and loses the selected value:The incorrect output is:
A row whose value is missing or false should produce a zero-valued element, but the reconstructed filter drops it. A truthy value should reach
float, but the incorrect output substitutes0.0.The distinction is also visible in these smaller examples:
The first two always produce one element per iteration, while the third can reject an iteration. In a COPY/conditional-jump sequence, the retained operand and following discard prove a value-preserving Boolean expression. Optional Boolean conversion instructions do not change that distinction.
The inline-comprehension merger now records whether a pending value merge is
and,oror a ternary, and builds the matching AST at the merge. Anand/orfold consumes one right-hand value, unlike a ternary's two arms. This also preserves selected operands and call order in[row.first() or row.second() for row in rows], and supports set elements and dictionary values.List-comprehension syntax begins in Python 2.0. The repaired instruction layout starts in Python 3.12, which introduces inlined comprehensions and removes
JUMP_IF_FALSE_OR_POP/JUMP_IF_TRUE_OR_POP; it is not exclusive to 3.14. See PEP 709 and Python 3.12's bytecode changes.