mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Reverse order of __contains__
arguments (#14424)
## Summary Closes https://github.com/astral-sh/ruff/issues/14423.
This commit is contained in:
parent
c46555da41
commit
fccbe56d23
3 changed files with 19 additions and 2 deletions
|
@ -100,3 +100,5 @@ class Thing:
|
|||
blah = lambda: {"a": 1}.__delitem__("a") # OK
|
||||
|
||||
blah = dict[{"a": 1}.__delitem__("a")] # OK
|
||||
|
||||
"abc".__contains__("a")
|
||||
|
|
|
@ -248,7 +248,7 @@ impl DunderReplacement {
|
|||
match dunder_method {
|
||||
"__add__" => Some(Self::Operator("+", "Use `+` operator")),
|
||||
"__and__" => Some(Self::Operator("&", "Use `&` operator")),
|
||||
"__contains__" => Some(Self::Operator("in", "Use `in` operator")),
|
||||
"__contains__" => Some(Self::ROperator("in", "Use `in` operator")),
|
||||
"__eq__" => Some(Self::Operator("==", "Use `==` operator")),
|
||||
"__floordiv__" => Some(Self::Operator("//", "Use `//` operator")),
|
||||
"__ge__" => Some(Self::Operator(">=", "Use `>=` operator")),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
||||
snapshot_kind: text
|
||||
---
|
||||
unnecessary_dunder_call.py:4:7: PLC2801 [*] Unnecessary dunder call to `__add__`. Use `+` operator.
|
||||
|
|
||||
|
@ -1082,3 +1081,19 @@ unnecessary_dunder_call.py:92:16: PLC2801 Unnecessary dunder call to `__getattri
|
|||
94 | def use_descriptor(self, item):
|
||||
|
|
||||
= help: Access attribute directly or use getattr built-in function
|
||||
|
||||
unnecessary_dunder_call.py:104:1: PLC2801 [*] Unnecessary dunder call to `__contains__`. Use `in` operator.
|
||||
|
|
||||
102 | blah = dict[{"a": 1}.__delitem__("a")] # OK
|
||||
103 |
|
||||
104 | "abc".__contains__("a")
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ PLC2801
|
||||
|
|
||||
= help: Use `in` operator
|
||||
|
||||
ℹ Unsafe fix
|
||||
101 101 |
|
||||
102 102 | blah = dict[{"a": 1}.__delitem__("a")] # OK
|
||||
103 103 |
|
||||
104 |-"abc".__contains__("a")
|
||||
104 |+"a" in "abc"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue