Skip to content

Consider if expression for parenthesized with items parsing#11010

Merged
dhruvmanila merged 1 commit intomainfrom
dhruv/with-items-if-expr
Apr 18, 2024
Merged

Consider if expression for parenthesized with items parsing#11010
dhruvmanila merged 1 commit intomainfrom
dhruv/with-items-if-expr

Conversation

@dhruvmanila
Copy link
Copy Markdown
Member

Summary

This PR fixes the bug in parenthesized with items parsing where the if expression would result into a syntax error.

The reason being that once we identify that the ambiguous left parenthesis belongs to the context expression, the parser converts the parsed with item into an equivalent expression. Then, the parser continuous to parse any postfix expressions. Now, attribute, subscript, and call are taken into account as they're grouped in parse_postfix_expression but if expression has it's own parsing function.

Use parse_if_expression once all postfix expressions have been parsed. Ideally, I think that if could be included in postfix expression parsing as they can be chained as well (x if True else y if True else z).

Test Plan

Add test cases and verified the snapshots.

@dhruvmanila dhruvmanila added bug Something isn't working parser Related to the parser labels Apr 18, 2024
@dhruvmanila dhruvmanila enabled auto-merge (squash) April 18, 2024 14:25
@dhruvmanila dhruvmanila merged commit 6c4d779 into main Apr 18, 2024
@dhruvmanila dhruvmanila deleted the dhruv/with-items-if-expr branch April 18, 2024 14:30
@github-actions
Copy link
Copy Markdown
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser Related to the parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants