-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FURB131 (previously `no-del`) has been broken for a while, basically since it's initial creation. #239 fixed some of this, but introduced improper semantics by implying you could use `del x[:]` when `x` is a `dict`, which is not true. This means that FURB131 only really applies to `list` types now (or any sequence that implements `.clear()`, though this isn't supported yet). I recently came across a similar idiom for clearing an array, `x[:] = []`, which is about twice as slow as `x.clear()`, and similar in nature to `del x[:]`. This new update was what prompted me to fix all the broken logic. With that in mind, this check has been renamed to `use-clear` since it no longer is about the `del` statement, but about using slices to clear a list. This shouldn't cause any issues since the name of checks are only used for display purposes. This will break any hyperlinks to FURB131 in the docs, though you'll still end up on the same page so I'm not too concerned about that.
- Loading branch information
Showing
5 changed files
with
59 additions
and
31 deletions.
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
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 |
---|---|---|
@@ -1,17 +1,29 @@ | ||
names = {"key": "value"} | ||
nums = [1, 2, 3] | ||
|
||
# these should match | ||
|
||
del nums[:] | ||
|
||
nums[:] = [] | ||
|
||
|
||
# these should not | ||
|
||
names = {"key": "value"} | ||
|
||
del names["key"] | ||
del names[:] # type: ignore | ||
|
||
del nums[0] | ||
|
||
x = 1 | ||
del x | ||
|
||
del nums[1:2] | ||
del nums[1:] | ||
del nums[:1] | ||
del nums[::1] | ||
|
||
nums[:] = [1, 2, 3] | ||
nums[1:] = [] | ||
nums[:1] = [] | ||
nums[::1] = [] |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
test/data/err_131.py:6:1 [FURB131]: Replace `del nums[:]` with `nums.clear()` | ||
test/data/err_131.py:5:1 [FURB131]: Replace `del nums[:]` with `nums.clear()` | ||
test/data/err_131.py:7:1 [FURB131]: Replace `nums[:] = []` with `nums.clear()` |