-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add autofix for PLR1701
(repeated-isinstance-calls)
#4792
Merged
charliermarsh
merged 5 commits into
astral-sh:main
from
dhruvmanila:feat/PLR1701/autofix
Jun 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
08940d4
Add autofix for `PLR1701` (repeated-isinstance-calls)
dhruvmanila a04d78b
Merge branch 'main' into feat/PLR1701/autofix
charliermarsh eca159f
Tweak message
charliermarsh 546775b
Move around
charliermarsh 043914a
Late isinstance check
charliermarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...uff/src/rules/pylint/snapshots/ruff__rules__pylint__tests__repeated_isinstance_calls.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
--- | ||
source: crates/ruff/src/rules/pylint/mod.rs | ||
--- | ||
repeated_isinstance_calls.py:15:8: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[3], (float, int))` | ||
| | ||
15 | # not merged | ||
16 | if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
17 | pass | ||
18 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
| | ||
= help: Replace with `isinstance(var[3], (float, int))` | ||
|
||
ℹ Fix | ||
12 12 | result = isinstance(var[2], (int, float)) | ||
13 13 | | ||
14 14 | # not merged | ||
15 |- if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] | ||
15 |+ if isinstance(var[3], (float, int)): # [consider-merging-isinstance] | ||
16 16 | pass | ||
17 17 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
18 18 | | ||
|
||
repeated_isinstance_calls.py:17:14: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[4], (float, int))` | ||
| | ||
17 | if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] | ||
18 | pass | ||
19 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
20 | | ||
21 | result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] | ||
| | ||
= help: Replace with `isinstance(var[4], (float, int))` | ||
|
||
ℹ Fix | ||
14 14 | # not merged | ||
15 15 | if isinstance(var[3], int) or isinstance(var[3], float) or isinstance(var[3], list) and True: # [consider-merging-isinstance] | ||
16 16 | pass | ||
17 |- result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
17 |+ result = isinstance(var[4], (float, int)) # [consider-merging-isinstance] | ||
18 18 | | ||
19 19 | result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] | ||
20 20 | | ||
|
||
repeated_isinstance_calls.py:19:14: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[5], (float, int))` | ||
| | ||
19 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
20 | | ||
21 | result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
22 | | ||
23 | inferred_isinstance = isinstance | ||
| | ||
= help: Replace with `isinstance(var[5], (float, int))` | ||
|
||
ℹ Fix | ||
16 16 | pass | ||
17 17 | result = isinstance(var[4], int) or isinstance(var[4], float) or isinstance(var[5], list) and False # [consider-merging-isinstance] | ||
18 18 | | ||
19 |- result = isinstance(var[5], int) or True or isinstance(var[5], float) # [consider-merging-isinstance] | ||
19 |+ result = isinstance(var[5], (float, int)) # [consider-merging-isinstance] | ||
20 20 | | ||
21 21 | inferred_isinstance = isinstance | ||
22 22 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] | ||
|
||
repeated_isinstance_calls.py:23:14: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[10], (list, str))` | ||
| | ||
23 | inferred_isinstance = isinstance | ||
24 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] | ||
25 | result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
26 | result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] | ||
| | ||
= help: Replace with `isinstance(var[10], (list, str))` | ||
|
||
ℹ Fix | ||
20 20 | | ||
21 21 | inferred_isinstance = isinstance | ||
22 22 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] | ||
23 |- result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] | ||
23 |+ result = isinstance(var[10], (list, str)) # [consider-merging-isinstance] | ||
24 24 | result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] | ||
25 25 | | ||
26 26 | result = isinstance(var[20]) | ||
|
||
repeated_isinstance_calls.py:24:14: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[11], (float, int))` | ||
| | ||
24 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] | ||
25 | result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] | ||
26 | result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
27 | | ||
28 | result = isinstance(var[20]) | ||
| | ||
= help: Replace with `isinstance(var[11], (float, int))` | ||
|
||
ℹ Fix | ||
21 21 | inferred_isinstance = isinstance | ||
22 22 | result = inferred_isinstance(var[6], int) or inferred_isinstance(var[6], float) or inferred_isinstance(var[6], list) and False # [consider-merging-isinstance] | ||
23 23 | result = isinstance(var[10], str) or isinstance(var[10], int) and var[8] * 14 or isinstance(var[10], float) and var[5] * 14.4 or isinstance(var[10], list) # [consider-merging-isinstance] | ||
24 |- result = isinstance(var[11], int) or isinstance(var[11], int) or isinstance(var[11], float) # [consider-merging-isinstance] | ||
24 |+ result = isinstance(var[11], (float, int)) # [consider-merging-isinstance] | ||
25 25 | | ||
26 26 | result = isinstance(var[20]) | ||
27 27 | result = isinstance() | ||
|
||
repeated_isinstance_calls.py:30:14: PLR1701 [*] Consider merging these isinstance calls to `isinstance(var[12], (float, int, list))` | ||
| | ||
30 | # Combination merged and not merged | ||
31 | result = isinstance(var[12], (int, float)) or isinstance(var[12], list) # [consider-merging-isinstance] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLR1701 | ||
32 | | ||
33 | # not merged but valid | ||
| | ||
= help: Replace with `isinstance(var[12], (float, int, list))` | ||
|
||
ℹ Fix | ||
27 27 | result = isinstance() | ||
28 28 | | ||
29 29 | # Combination merged and not merged | ||
30 |- result = isinstance(var[12], (int, float)) or isinstance(var[12], list) # [consider-merging-isinstance] | ||
30 |+ result = isinstance(var[12], (float, int, list)) # [consider-merging-isinstance] | ||
31 31 | | ||
32 32 | # not merged but valid | ||
33 33 | result = isinstance(var[5], int) and var[5] * 14 or isinstance(var[5], float) and var[5] * 14.4 | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we use the AST to build this or is it fine to format it directly?
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.
I think either would be reasonable.