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 each comprehension filter's polarity when its acceptance edge leads to another filter. The code below currently decompiles with its first two tests inverted:
The incorrect output is:
This selects different rows and changes which comparison and method calls run. For example, a matching row no longer reaches
ready(), while a nonmatching row can reach it and raise an exception that the source skips.A forward jump accepting the first filter can land at the next filter rather than at append. The parser's scan onward for append can encounter that later filter's rejection edge and invert the first filter. The fix first proves the current fallthrough's exact padding/back-edge trampoline to the current comprehension loop. That identifies the current jump's acceptance/rejection polarity without adopting later filters' control flow.
Variations include
!=,not row.ready(), oneand-joined filter versus multipleifclauses, and list, set and dictionary comprehensions. Both same-line and line-broken filters retain their short-circuit order.The additional recognition starts at Python 3.12, matching the introduction of inlined comprehensions in PEP 709. The earlier separate-code-object path retains its existing handling.