Skip to content

Commit

Permalink
Allow descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 5, 2024
1 parent 49a9745 commit 308d0ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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)


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,7 +288,6 @@ 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(
Expand Down Expand Up @@ -329,7 +331,6 @@ fn allow_nested_expression(dunder_name: &str, semantic: &SemanticModel) -> bool
"__init__"
| "__del__"
| "__delattr__"
| "__set__"
| "__delete__"
| "__setitem__"
| "__delitem__"
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

0 comments on commit 308d0ab

Please sign in to comment.