I've made a classproperty
descriptor and whenever I use a function decorated with it, I get multiple pylint
inspection errors.
Here is a sample class with a sample decorated function:
class Bar:
"""
Bar documentation.
"""
# pylint: disable=no-method-argument
@classproperty
def foo():
"""
Retrieve foo.
"""
return "foo"
Thanks to the descriptor, I can call Bar.foo
and get the string foo returned.
Unfortunately, whenever I use functions like this with slightly more complex items (e.g. functions which return instances of objects), pylint
starts complaining about things such as no-member
or unexpected-keyword-arg
, simply because it thinks Bar.foo
is a method, rather than a wrapped classproperty
object.
I would like to disable warnings for any code that uses my function - I definitely can't allow having to write # pylint: disable
every single time I use the classproperty
-wrapped methods. How can I do it with pylint
? Or maybe I should switch to use a different linter instead?
Here is an example of a warning generated because of the reasons above:
class Bar:
"""
Bar documentation.
"""
# pylint: disable=no-method-argument
@classproperty
def foo():
"""
Retrieve an object.
"""
return NotImplementedError("Argument")
print(Bar.foo.args)
pylint
complains that E1101: Method 'foo' has no 'args' member (no-member)
(even though I know it definitely has), and I would like to completely disable some warnings for any module/class/function that uses Bar.foo.args
or similar.
For anyone interested, here is a minimal implementation of a classproperty
descriptor:
class classproperty:
"""
Minimal descriptor.
"""
# pylint: disable=invalid-name
def __init__(self, func):
self._func = func
def __get__(self, _obj, _type):
return self._func()