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

Expect , for parenthesized with items and not at ) #10910

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Apr 12, 2024

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.

@dhruvmanila dhruvmanila added bug Something isn't working parser Related to the parser fuzzer Surfaced via fuzzing. labels Apr 12, 2024
Copy link
Contributor

github-actions bot commented Apr 12, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+33 -92 violations, +0 -0 fixes in 10 projects; 34 projects unchanged)

aiven/aiven-client (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- aiven/client/client.py:159:9: PLR6104 Use `+=` to perform an augmented assignment directly

apache/airflow (+0 -11 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- airflow/models/taskinstance.py:1653:21: PLR6104 Use `/=` to perform an augmented assignment directly
- airflow/providers/apache/hive/hooks/hive.py:346:21: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/apache/hive/hooks/hive.py:348:21: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/elasticsearch/log/es_task_handler.py:207:13: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/providers/fab/auth_manager/security_manager/override.py:2041:21: PLR6104 Use `%=` to perform an augmented assignment directly
- airflow/providers/microsoft/azure/utils.py:184:9: PLR6104 Use `+=` to perform an augmented assignment directly
- airflow/utils/operator_helpers.py:112:17: PLR6104 Use `+=` to perform an augmented assignment directly
- dev/breeze/src/airflow_breeze/commands/release_management_commands.py:3196:5: PLR6104 Use `+=` to perform an augmented assignment directly
- dev/breeze/src/airflow_breeze/utils/kubernetes_utils.py:257:5: PLR6104 Use `+=` to perform an augmented assignment directly
- dev/breeze/src/airflow_breeze/utils/kubernetes_utils.py:419:5: PLR6104 Use `+=` to perform an augmented assignment directly
... 1 additional changes omitted for project

aws/aws-sam-cli (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ samcli/lib/observability/cw_logs/cw_log_puller.py:136:17: PLR1730 [*] Replace `if` statement with `max` call
+ samcli/lib/observability/xray_traces/xray_event_puller.py:163:21: PLR1730 [*] Replace `if` statement with `max` call
+ samcli/lib/observability/xray_traces/xray_events.py:52:13: PLR1730 [*] Replace `if` statement with `max` call
+ samcli/lib/observability/xray_traces/xray_events.py:87:13: PLR1730 [*] Replace `if` statement with `max` call

bokeh/bokeh (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- src/bokeh/embed/server.py:294:9: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/tornado.py:307:13: PLR6104 Use `+=` to perform an augmented assignment directly
- src/bokeh/server/tornado.py:422:17: PLR6104 Use `+=` to perform an augmented assignment directly

freedomofpress/securedrop (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- securedrop/pretty_bad_protocol/_util.py:462:5: PLR6104 Use `%=` to perform an augmented assignment directly

ibis-project/ibis (+0 -4 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- ibis/backends/druid/__init__.py:61:9: PLR6104 Use `|=` to perform an augmented assignment directly
- ibis/backends/exasol/__init__.py:105:9: PLR6104 Use `|=` to perform an augmented assignment directly
- ibis/common/annotations.py:287:13: PLR6104 Use `+=` to perform an augmented assignment directly
- ibis/common/annotations.py:289:13: PLR6104 Use `+=` to perform an augmented assignment directly

pandas-dev/pandas (+0 -47 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- pandas/_testing/contexts.py:113:5: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:107:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:168:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:200:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/compat/numpy/function.py:229:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/core/arrays/masked.py:693:13: PLR6104 Use `|=` to perform an augmented assignment directly
- pandas/core/groupby/groupby.py:1973:13: PLR6104 Use `-=` to perform an augmented assignment directly
- pandas/core/groupby/groupby.py:4502:13: PLR6104 Use `-=` to perform an augmented assignment directly
- pandas/core/indexes/datetimes.py:665:13: PLR6104 Use `&=` to perform an augmented assignment directly
- pandas/core/indexes/multi.py:3590:13: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/core/indexes/range.py:455:13: PLR6104 Use `-=` to perform an augmented assignment directly
- pandas/core/methods/selectn.py:171:13: PLR6104 Use `-=` to perform an augmented assignment directly
- pandas/core/window/numba_.py:152:29: PLR6104 Use `*=` to perform an augmented assignment directly
- pandas/core/window/numba_.py:327:29: PLR6104 Use `*=` to perform an augmented assignment directly
- pandas/core/window/rolling.py:827:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/core/window/rolling.py:828:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/core/window/rolling.py:829:9: PLR6104 Use `+=` to perform an augmented assignment directly
- pandas/io/formats/format.py:344:13: PLR6104 Use `+=` to perform an augmented assignment directly
... 29 additional changes omitted for project

rotki/rotki (+27 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ rotkehlchen/chain/bitcoin/bch/utils.py:132:97: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
+ rotkehlchen/chain/bitcoin/bch/utils.py:58:93: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
+ rotkehlchen/chain/ethereum/graph.py:71:88: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
+ rotkehlchen/chain/ethereum/modules/eth2/beacon.py:76:105: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
+ rotkehlchen/chain/evm/decoding/utils.py:42:13: PLR1730 [*] Replace `if` statement with `max` call
+ rotkehlchen/chain/evm/node_inquirer.py:301:173: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
+ rotkehlchen/db/accounting_rules.py:268:120: RUF100 [*] Unused `noqa` directive (unused: `PLR6104`)
... 21 additional changes omitted for rule RUF100
... 20 additional changes omitted for project

zulip/zulip (+1 -11 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL

- analytics/lib/fixtures.py:77:13: PLR6104 Use `+=` to perform an augmented assignment directly
- tools/lib/pretty_print.py:134:13: PLR6104 Use `+=` to perform an augmented assignment directly
- zerver/lib/cache.py:185:9: PLR6104 Use `+=` to perform an augmented assignment directly
- zerver/lib/ccache.py:43:9: PLR6104 Use `+=` to perform an augmented assignment directly
- zerver/lib/ccache.py:45:5: PLR6104 Use `+=` to perform an augmented assignment directly
- zerver/lib/ccache.py:70:9: PLR6104 Use `+=` to perform an augmented assignment directly
... 6 additional changes omitted for rule PLR6104
+ zerver/tests/test_openapi.py:344:13: PLR1730 [*] Replace `if` statement with `val = min(v, val)`
... 5 additional changes omitted for project

indico/indico (+1 -14 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

- indico/core/logger.py:122:13: PLR6104 Use `+=` to perform an augmented assignment directly
- indico/modules/attachments/blueprint.py:100:13: PLR6104 Use `+=` to perform an augmented assignment directly
- indico/modules/attachments/blueprint.py:59:13: PLR6104 Use `+=` to perform an augmented assignment directly
- indico/modules/attachments/blueprint.py:61:13: PLR6104 Use `+=` to perform an augmented assignment directly
- indico/modules/attachments/blueprint.py:98:13: PLR6104 Use `+=` to perform an augmented assignment directly
- indico/modules/events/management/blueprint.py:79:9: PLR6104 Use `+=` to perform an augmented assignment directly
... 9 additional changes omitted for rule PLR6104
+ indico/modules/receipts/controllers/templates.py:218:17: PLR1730 [*] Replace `if` statement with `max_index = max(index, max_index)`
... 8 additional changes omitted for project

Changes by rule (3 rules affected)

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.

@dhruvmanila dhruvmanila marked this pull request as ready for review April 12, 2024 15:18
Comment on lines +2070 to +2078
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);
}
Copy link
Member Author

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.

@dhruvmanila dhruvmanila merged commit bd3c326 into dhruv/parser Apr 15, 2024
3 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/with-item-expect-comma branch April 15, 2024 12:40
dhruvmanila added a commit that referenced this pull request Apr 16, 2024
## 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.
dhruvmanila added a commit that referenced this pull request Apr 16, 2024
## 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.
dhruvmanila added a commit that referenced this pull request Apr 17, 2024
## 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.
dhruvmanila added a commit that referenced this pull request Apr 18, 2024
## 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.
dhruvmanila added a commit that referenced this pull request Apr 18, 2024
(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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzer Surfaced via fuzzing. parser Related to the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants