Repository navigation
Allow general expressions in PEP 798 dict comprehension unpacking (#30406) - #30418
Open
viliamgonda wants to merge 1 commit into
Open
viliamgonda wants to merge 1 commit into
viliamgonda wants to merge 1 commit into
Conversation
…king (astral-sh#30406) In PEP 798, dictionary comprehension unpacking uses the general expression rule ('**' expression for_if_clauses), unlike dictionary displays which restrict unpacking operands to bitwise OR precedence ('**' bitwise_or). Defer bitwise OR precedence validation in parse_set_or_dict_like_expression until after checking whether the expression is followed by comprehension clauses ('for' / 'async'). Closes astral-sh#30406.
viliamgonda
requested review from
MichaReiser and
dhruvmanila
as code owners
November 13, 2026 19:29
This branch has not been deployed
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.
Summary
Closes #30406.
In PEP 798, dictionary comprehension unpacking uses the general expression grammar rule (
'**' expression for_if_clauses), whereas dictionary displays restrict unpacking operands to bitwise OR precedence ('**' bitwise_or).parse_set_or_dict_like_expressionpreviously calledparse_expression_with_bitwise_or_precedence()immediately upon encountering**. This prematurely rejected valid unparenthesized boolean expressions (e.g.{**x or {} for x in []},{**not x for x in []}) withBoolean expression cannot be used herebefore determining whether the construct was a dictionary comprehension.Refactor bitwise OR precedence validation into
validate_bitwise_or_precedenceand defer it until after checking whether the expression is followed by comprehension clauses (for/async).