-
Notifications
You must be signed in to change notification settings - Fork 892
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
Expect ,
for parenthesized with items and not at )
#10910
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR6104 | 92 | 0 | 92 | 0 | 0 |
RUF100 | 26 | 26 | 0 | 0 | 0 |
PLR1730 | 7 | 7 | 0 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
8f8c388
to
b953da8
Compare
if with_item_kind == WithItemKind::Parenthesized && !self.at(TokenKind::Rpar) { | ||
// test_err with_items_parenthesized_missing_comma | ||
// with (item1 item2): ... | ||
// with (item1 as f1 item2): ... | ||
// with (item1, item2 item3, item4): ... | ||
// with (item1, item2 as f1 item3, item4): ... | ||
// with (item1, item2: ... | ||
self.expect(TokenKind::Comma); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only the case for the first "gap" as any other missing commas will be highlighted by the list parsing in parse_with_items
.
cefa753
to
509be82
Compare
b953da8
to
faf94e2
Compare
## Summary This PR fixes a bug in parenthesized with-items parsing where the parser should expect a comma but it didn't. This is the case in the speculative parsing loop of parenthesized with-items. Once the parser finds any token other than comma, it breaks out of the loop. Then, once the parser has determined the with item kind, it needs to expect a comma if it's not the end of parenthesized with-items. ## Test Plan Add inline test cases, verify the snapshots.
## Summary This PR fixes a bug in parenthesized with-items parsing where the parser should expect a comma but it didn't. This is the case in the speculative parsing loop of parenthesized with-items. Once the parser finds any token other than comma, it breaks out of the loop. Then, once the parser has determined the with item kind, it needs to expect a comma if it's not the end of parenthesized with-items. ## Test Plan Add inline test cases, verify the snapshots.
## Summary This PR fixes a bug in parenthesized with-items parsing where the parser should expect a comma but it didn't. This is the case in the speculative parsing loop of parenthesized with-items. Once the parser finds any token other than comma, it breaks out of the loop. Then, once the parser has determined the with item kind, it needs to expect a comma if it's not the end of parenthesized with-items. ## Test Plan Add inline test cases, verify the snapshots.
## Summary This PR fixes a bug in parenthesized with-items parsing where the parser should expect a comma but it didn't. This is the case in the speculative parsing loop of parenthesized with-items. Once the parser finds any token other than comma, it breaks out of the loop. Then, once the parser has determined the with item kind, it needs to expect a comma if it's not the end of parenthesized with-items. ## Test Plan Add inline test cases, verify the snapshots.
(Supersedes #9152, authored by @LaBatata101) ## Summary This PR replaces the current parser generated from LALRPOP to a hand-written recursive descent parser. It also updates the grammar for [PEP 646](https://peps.python.org/pep-0646/) so that the parser outputs the correct AST. For example, in `data[*x]`, the index expression is now a tuple with a single starred expression instead of just a starred expression. Beyond the performance improvements, the parser is also error resilient and can provide better error messages. The behavior as seen by any downstream tools isn't changed. That is, the linter and formatter can still assume that the parser will _stop_ at the first syntax error. This will be updated in the following months. For more details about the change here, refer to the PR corresponding to the individual commits and the release blog post. ## Test Plan Write _lots_ and _lots_ of tests for both valid and invalid syntax and verify the output. ## Acknowledgements - @MichaReiser for reviewing 100+ parser PRs and continuously providing guidance throughout the project - @LaBatata101 for initiating the transition to a hand-written parser in #9152 - @addisoncrump for implementing the fuzzer which helped [catch](#10903) [a](#10910) [lot](#10966) [of](#10896) [bugs](#10877) --------- Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org> Co-authored-by: Micha Reiser <micha@reiser.io>
Summary
This PR fixes a bug in parenthesized with-items parsing where the parser should expect a comma but it didn't.
This is the case in the speculative parsing loop of parenthesized with-items. Once the parser finds any token other than comma, it breaks out of the loop. Then, once the parser has determined the with item kind, it needs to expect a comma if it's not the end of parenthesized with-items.
Test Plan
Add inline test cases, verify the snapshots.