-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[ruff
] Expand rule for list(iterable).pop(0)
idiom (RUF015
)
#10148
Merged
charliermarsh
merged 6 commits into
astral-sh:main
from
robincaloudis:rc-extension-ruf015
Feb 28, 2024
Merged
[ruff
] Expand rule for list(iterable).pop(0)
idiom (RUF015
)
#10148
charliermarsh
merged 6 commits into
astral-sh:main
from
robincaloudis:rc-extension-ruf015
Feb 28, 2024
Conversation
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 little test makes sure that we have something to test against when extending the rule.
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLR0902 | 802 | 0 | 802 | 0 | 0 |
robincaloudis
commented
Feb 27, 2024
.../ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF015_RUF015.py.snap
Outdated
Show resolved
Hide resolved
This implementation makes the test pass again.
robincaloudis
force-pushed
the
rc-extension-ruf015
branch
from
February 27, 2024 22:59
0f53fee
to
ca9b2ab
Compare
charliermarsh
approved these changes
Feb 28, 2024
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.
Thanks!
charliermarsh
force-pushed
the
rc-extension-ruf015
branch
from
February 28, 2024 00:16
2003ed7
to
76d62d8
Compare
charliermarsh
changed the title
[ruff] Expand rule for
[Feb 28, 2024
list(iterable).pop(0)
idiom (RUF015)ruff
] Expand rule for list(iterable).pop(0)
idiom (RUF015
)
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
…tral-sh#10148) ## Summary Currently, rule `RUF015` is not able to detect the usage of `list(iterable).pop(0)` falling under the category of an _unnecessary iterable allocation for accessing the first element_. This PR wants to change that. See the underlying issue for more details. * Provide extension to detect `list(iterable).pop(0)`, but not `list(iterable).pop(i)` where i > 1 * Update corresponding doc ## Test Plan * `RUF015.py` and the corresponding snap file were extended such that their correspond to the new behaviour Closes astral-sh#9190 --- PS: I've only been working on this ticket as I haven't seen any activity from issue assignee @rmad17, neither in this repo nor in a fork. I hope I interpreted his inactivity correctly. Didn't mean to steal his chance. Since I stumbled across the underlying problem myself, I wanted to offer a solution as soon as possible.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Currently, rule
RUF015
is not able to detect the usage oflist(iterable).pop(0)
falling under the category of an unnecessary iterable allocation for accessing the first element. This PR wants to change that. See the underlying issue for more details.list(iterable).pop(0)
, but notlist(iterable).pop(i)
where i > 1Test Plan
RUF015.py
and the corresponding snap file were extended such that their correspond to the new behaviourCloses #9190
PS: I've only been working on this ticket as I haven't seen any activity from issue assignee @rmad17, neither in this repo nor in a fork. I hope I interpreted his inactivity correctly. Didn't mean to steal his chance. Since I stumbled across the underlying problem myself, I wanted to offer a solution as soon as possible.