Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider if expression for parenthesized with items parsing #11010

Merged
merged 1 commit into from Apr 18, 2024

Conversation

dhruvmanila
Copy link
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
17 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/with-items-if-expr branch April 18, 2024 14:30
Copy link
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.

None yet

2 participants