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

Fix formatter panic with comment after parenthesized dict value #5293

Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented Jun 22, 2023

Summary

This snippet used to panic because it expected to see a comma or something similar after the 2 but met the closing parentheses that is not part of the range and panicked

a = {
    1: (2),
    # comment
    3: True,
}

Originally found in https://github.com/bolucat/Firefox/blob/636a717ef025c16434997dc89e42351ef740ee6b/testing/marionette/client/marionette_driver/geckoinstance.py#L109

This snippet is also the test plan.

@konstin
Copy link
Member Author

konstin commented Jun 22, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@github-actions
Copy link

github-actions bot commented Jun 22, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.02      7.1±0.02ms     5.7 MB/sec    1.00      7.0±0.02ms     5.8 MB/sec
formatter/numpy/ctypeslib.py               1.01   1494.0±3.27µs    11.1 MB/sec    1.00   1474.8±5.13µs    11.3 MB/sec
formatter/numpy/globals.py                 1.01    163.0±3.43µs    18.1 MB/sec    1.00    161.1±0.17µs    18.3 MB/sec
formatter/pydantic/types.py                1.03      3.5±0.01ms     7.2 MB/sec    1.00      3.5±0.01ms     7.4 MB/sec
linter/all-rules/large/dataset.py          1.00     13.7±0.04ms     3.0 MB/sec    1.01     13.8±0.08ms     3.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.4±0.01ms     4.8 MB/sec    1.00      3.5±0.01ms     4.8 MB/sec
linter/all-rules/numpy/globals.py          1.00    358.3±1.36µs     8.2 MB/sec    1.00    359.2±0.92µs     8.2 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.0±0.02ms     4.2 MB/sec    1.00      6.0±0.02ms     4.2 MB/sec
linter/default-rules/large/dataset.py      1.00      7.0±0.02ms     5.8 MB/sec    1.01      7.1±0.05ms     5.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1459.0±2.49µs    11.4 MB/sec    1.00   1463.8±1.83µs    11.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    154.8±0.17µs    19.1 MB/sec    1.01    155.9±0.13µs    18.9 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.2±0.03ms     8.0 MB/sec    1.00      3.2±0.02ms     8.0 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01      7.9±0.11ms     5.1 MB/sec    1.00      7.9±0.10ms     5.2 MB/sec
formatter/numpy/ctypeslib.py               1.01  1692.8±55.77µs     9.8 MB/sec    1.00  1682.9±22.68µs     9.9 MB/sec
formatter/numpy/globals.py                 1.00    185.7±5.08µs    15.9 MB/sec    1.02    188.5±8.82µs    15.7 MB/sec
formatter/pydantic/types.py                1.00      3.9±0.05ms     6.5 MB/sec    1.01      4.0±0.07ms     6.4 MB/sec
linter/all-rules/large/dataset.py          1.00     15.5±0.16ms     2.6 MB/sec    1.01     15.7±0.27ms     2.6 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.1±0.07ms     4.1 MB/sec    1.00      4.1±0.09ms     4.1 MB/sec
linter/all-rules/numpy/globals.py          1.00   492.3±11.89µs     6.0 MB/sec    1.01   497.6±10.39µs     5.9 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.0±0.16ms     3.7 MB/sec    1.01      7.1±0.12ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.1±0.12ms     5.0 MB/sec    1.01      8.1±0.10ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1719.7±31.05µs     9.7 MB/sec    1.01  1730.5±23.82µs     9.6 MB/sec
linter/default-rules/numpy/globals.py      1.01    197.3±5.84µs    15.0 MB/sec    1.00    196.1±3.15µs    15.0 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.7±0.06ms     6.9 MB/sec    1.00      3.6±0.04ms     7.0 MB/sec

..
}
));
while let Some(first) = tokens.next() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add '{'.text_len() on line 982 instead of skipping over the { in the iteration?

Copy link
Member Author

@konstin konstin Jun 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried it, but this didn't work for me

@konstin konstin force-pushed the Fix_formatter_panic_with_comment_after_parenthesized_dict_value branch from d6f0cd1 to 8010d93 Compare June 22, 2023 11:08
## Summary

This snippet used to panic because it expected to see a comma or something similar after the `2` but met the closing parentheses that is not part of the range and panicked
```python
a = {
    1: (2),
    # comment
    3: True,
}
```

Originally found in https://github.com/bolucat/Firefox/blob/636a717ef025c16434997dc89e42351ef740ee6b/testing/marionette/client/marionette_driver/geckoinstance.py#L109

This snippet is also the test plan.
@konstin konstin force-pushed the Fix_formatter_panic_with_comment_after_parenthesized_dict_value branch from 8010d93 to b963c7f Compare June 22, 2023 12:58
@konstin konstin merged commit d407165 into main Jun 22, 2023
16 checks passed
@konstin konstin deleted the Fix_formatter_panic_with_comment_after_parenthesized_dict_value branch June 22, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants