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

Simplify ANN204 autofix to use Parameters range #6793

Merged
merged 2 commits into from
Aug 23, 2023
Merged

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Aug 22, 2023

Summary

This PR fixes the bug where the decorator parentheses weren't being considered
when computing the autofix for ANN204. The existing logic would only look
for balanced parentheses and not multiple pairs of parentheses.

The solution is to remove the logic to generate the autofix and use the Parameters
end range directly which includes the parentheses as well.

Test Plan

Add test case for ANN204 with decorator being called

fixes: #6790

@dhruvmanila
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 22, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      3.3±0.28ms    12.2 MB/sec    1.00      3.3±0.29ms    12.2 MB/sec
formatter/numpy/ctypeslib.py               1.00   697.5±44.88µs    23.9 MB/sec    1.00   699.5±43.19µs    23.8 MB/sec
formatter/numpy/globals.py                 1.00     72.3±4.29µs    40.8 MB/sec    1.03     74.7±5.90µs    39.5 MB/sec
formatter/pydantic/types.py                1.02  1384.6±87.08µs    18.4 MB/sec    1.00  1357.5±111.34µs    18.8 MB/sec
linter/all-rules/large/dataset.py          1.00      9.8±0.51ms     4.1 MB/sec    1.01      9.9±0.57ms     4.1 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      2.7±0.14ms     6.2 MB/sec    1.04      2.8±0.18ms     6.0 MB/sec
linter/all-rules/numpy/globals.py          1.00   375.4±28.85µs     7.9 MB/sec    1.02   383.0±21.46µs     7.7 MB/sec
linter/all-rules/pydantic/types.py         1.03      5.3±0.39ms     4.8 MB/sec    1.00      5.2±0.30ms     4.9 MB/sec
linter/default-rules/large/dataset.py      1.00      5.2±0.27ms     7.8 MB/sec    1.03      5.4±0.26ms     7.5 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1173.6±70.68µs    14.2 MB/sec    1.02  1202.9±87.96µs    13.8 MB/sec
linter/default-rules/numpy/globals.py      1.00   137.4±11.69µs    21.5 MB/sec    1.02   140.7±11.31µs    21.0 MB/sec
linter/default-rules/pydantic/types.py     1.00      2.4±0.15ms    10.7 MB/sec    1.02      2.4±0.15ms    10.5 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      3.7±0.06ms    10.9 MB/sec    1.01      3.8±0.07ms    10.8 MB/sec
formatter/numpy/ctypeslib.py               1.00   761.8±22.05µs    21.9 MB/sec    1.02   779.4±64.06µs    21.4 MB/sec
formatter/numpy/globals.py                 1.00     79.3±1.61µs    37.2 MB/sec    1.01     79.7±2.50µs    37.0 MB/sec
formatter/pydantic/types.py                1.00  1525.6±29.32µs    16.7 MB/sec    1.01  1545.9±26.06µs    16.5 MB/sec
linter/all-rules/large/dataset.py          1.01     13.0±0.17ms     3.1 MB/sec    1.00     12.8±0.19ms     3.2 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.5±0.03ms     4.7 MB/sec    1.00      3.5±0.04ms     4.8 MB/sec
linter/all-rules/numpy/globals.py          1.00    438.1±6.93µs     6.7 MB/sec    1.00    437.3±6.63µs     6.7 MB/sec
linter/all-rules/pydantic/types.py         1.01      6.7±0.25ms     3.8 MB/sec    1.00      6.7±0.09ms     3.8 MB/sec
linter/default-rules/large/dataset.py      1.01      7.2±0.09ms     5.6 MB/sec    1.00      7.1±0.07ms     5.7 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1522.1±21.98µs    10.9 MB/sec    1.00  1515.4±19.60µs    11.0 MB/sec
linter/default-rules/numpy/globals.py      1.00    174.8±3.14µs    16.9 MB/sec    1.01    177.1±3.52µs    16.7 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.2±0.05ms     7.9 MB/sec    1.00      3.2±0.05ms     7.9 MB/sec

@dhruvmanila dhruvmanila changed the title Consider decorator parentheses for ANN204 autofix Simplify ANN204 autofix to use Parameters range Aug 23, 2023
use ruff_source_file::Locator;

/// ANN204
pub(crate) fn add_return_annotation<T: Ranged>(
Copy link
Member

Choose a reason for hiding this comment

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

Awesome

@dhruvmanila dhruvmanila merged commit db2e548 into main Aug 23, 2023
16 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/ann204-autofix branch August 23, 2023 03:35
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.

Rules ANN204, EM101, W293 causes autofix error
2 participants