-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refurb] Implement
check-and-remove-from-set
rule (FURB132
)
- Loading branch information
1 parent
77ee1e6
commit a4ffa8c
Showing
9 changed files
with
425 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from typing import Set | ||
from some.package.name import foo, bar | ||
|
||
|
||
s = set() | ||
s2 = {} | ||
s3: set[int] = foo() | ||
|
||
# these should match | ||
|
||
# FURB132 | ||
if "x" in s: | ||
s.remove("x") | ||
|
||
|
||
# FURB132 | ||
if "x" in s2: | ||
s2.remove("x") | ||
|
||
|
||
# FURB132 | ||
if "x" in s3: | ||
s3.remove("x") | ||
|
||
|
||
var = "y" | ||
# FURB132 | ||
if var in s: | ||
s.remove(var) | ||
|
||
|
||
if f"{var}:{var}" in s: | ||
s.remove(f"{var}:{var}") | ||
|
||
|
||
def identity(x): | ||
return x | ||
|
||
|
||
# FURB132 | ||
if identity("x") in s2: | ||
s2.remove(identity("x")) | ||
|
||
|
||
# these should not | ||
|
||
if "x" in s: | ||
s.remove("y") | ||
|
||
s.discard("x") | ||
|
||
s2 = set() | ||
|
||
if "x" in s: | ||
s2.remove("x") | ||
|
||
if "x" in s: | ||
s.remove("x") | ||
print("removed item") | ||
|
||
if bar() in s: | ||
# bar() might have a side effect | ||
s.remove(bar()) | ||
|
||
if "x" in s: | ||
s.remove("x") | ||
else: | ||
print("not found") | ||
|
||
class Container: | ||
def remove(self, item) -> None: | ||
return | ||
|
||
def __contains__(self, other) -> bool: | ||
return True | ||
|
||
c = Container() | ||
|
||
if "x" in c: | ||
c.remove("x") |
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
Oops, something went wrong.