Reverse order of __contains__ arguments (#14424)

## Summary

Closes https://github.com/astral-sh/ruff/issues/14423.
This commit is contained in:
Charlie Marsh 2024-11-17 22:58:12 -05:00 committed by GitHub
parent c46555da41
commit fccbe56d23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View file

@ -100,3 +100,5 @@ class Thing:
blah = lambda: {"a": 1}.__delitem__("a") # OK
blah = dict[{"a": 1}.__delitem__("a")] # OK
"abc".__contains__("a")

View file

@ -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")),

View file

@ -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"