Is PLC2801 really supposed to trigger in this case, and suggest using a get method that does not exist? I can of course easily silence the rule, but just in case it's overzealous here I'm opening this issue.
class classproperty(property):
def __get__(self, obj, type=None):
return self.fget.__get__(None, type)()
class A:
@classproperty
@classmethod
def prop(cls):
return 'aaa'
class B:
prop = 'bbb'
class C:
pass
class Foo(A, B, C):
@classmethod
def test(cls):
for class_ in reversed(cls.mro()[:-1]):
prop = class_.__dict__.get('prop')
if isinstance(prop, classproperty):
prop = prop.__get__(None, class_)
print(class_.__name__, prop)
Foo.test()
[adrian@eluvian:~/dev/indico/py3/src:update-ruff +$]> ruff --version
ruff 0.2.0
[adrian@eluvian:~/dev/indico/py3/src:update-ruff +$]> ruff --isolated --select PLC2801 --preview --no-cache rufftest/ruff_sample.py
rufftest/ruff_sample.py:27:24: PLC2801 Unnecessary dunder call to `__get__`. Use `get` method.
|
25 | prop = class_.__dict__.get('prop')
26 | if isinstance(prop, classproperty):
27 | prop = prop.__get__(None, class_)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ PLC2801
28 | print(class_.__name__, prop)
|
= help: Use `get` method
Found 1 error.
Is PLC2801 really supposed to trigger in this case, and suggest using a
getmethod that does not exist? I can of course easily silence the rule, but just in case it's overzealous here I'm opening this issue.