Skip to content
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

Drop __get__ and __set__ from unnecessary-dunder-call #9791

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def __getattribute__(self, item):
def do_thing(self, item):
return object.__getattribute__(self, item) # PLC2801

def use_descriptor(self, item):
item.__get__(self, type(self)) # OK
item.__set__(self, 1) # OK
item.__delete__(self) # OK


blah = lambda: {"a": 1}.__delitem__("a") # OK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ fn allowed_dunder_constants(dunder_method: &str, target_version: PythonVersion)
| "__await__"
| "__class__"
| "__class_getitem__"
| "__delete__"
| "__dict__"
| "__doc__"
| "__exit__"
| "__get__"
| "__getnewargs__"
| "__getnewargs_ex__"
| "__getstate__"
Expand All @@ -185,6 +187,7 @@ fn allowed_dunder_constants(dunder_method: &str, target_version: PythonVersion)
| "__post_init__"
| "__reduce__"
| "__reduce_ex__"
| "__set__"
| "__set_name__"
| "__setstate__"
| "__sizeof__"
Expand Down Expand Up @@ -285,14 +288,12 @@ impl DunderReplacement {
"__deepcopy__" => Some(Self::MessageOnly("Use `copy.deepcopy()` function")),
"__del__" => Some(Self::MessageOnly("Use `del` statement")),
"__delattr__" => Some(Self::MessageOnly("Use `del` statement")),
"__delete__" => Some(Self::MessageOnly("Use `del` statement")),
"__delitem__" => Some(Self::MessageOnly("Use `del` statement")),
"__divmod__" => Some(Self::MessageOnly("Use `divmod()` builtin")),
"__format__" => Some(Self::MessageOnly(
"Use `format` builtin, format string method, or f-string",
)),
"__fspath__" => Some(Self::MessageOnly("Use `os.fspath` function")),
"__get__" => Some(Self::MessageOnly("Use `get` method")),
"__getattr__" => Some(Self::MessageOnly(
"Access attribute directly or use getattr built-in function",
)),
Expand All @@ -308,7 +309,6 @@ impl DunderReplacement {
"__pow__" => Some(Self::MessageOnly("Use ** operator or `pow()` builtin")),
"__rdivmod__" => Some(Self::MessageOnly("Use `divmod()` builtin")),
"__rpow__" => Some(Self::MessageOnly("Use ** operator or `pow()` builtin")),
"__set__" => Some(Self::MessageOnly("Use subscript assignment")),
"__setattr__" => Some(Self::MessageOnly(
"Mutate attribute directly or use setattr built-in function",
)),
Expand All @@ -331,8 +331,6 @@ fn allow_nested_expression(dunder_name: &str, semantic: &SemanticModel) -> bool
"__init__"
| "__del__"
| "__delattr__"
| "__set__"
| "__delete__"
| "__setitem__"
| "__delitem__"
| "__iadd__"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ unnecessary_dunder_call.py:31:16: PLC2801 Unnecessary dunder call to `__getattri
30 | def do_thing(self, item):
31 | return object.__getattribute__(self, item) # PLC2801
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PLC2801
32 |
33 | def use_descriptor(self, item):
|
= help: Access attribute directly or use getattr built-in function

Expand Down
Loading