Description
openedon Apr 13, 2020
The using-constant-test
warning shows up on uses of things that pylint does not understand are properties when it could not inspect the decorator implementation.
Reproduction
Given the following code, run pylint (2.4.4 in my case) on it. Note the comment.
module.py
#!/usr/bin/env python3
"""Module."""
# A PyPI package - run pylint in a venv _without_ this installed!
import cached_property
class Klass:
"""Klass."""
def __init__(self, arg):
self.arg = arg
def meth(self):
if self._condition:
print('truth')
@cached_property.cached_property
def _condition(self):
return bool(self.arg)
def main():
k = Klass(1)
k.meth()
if __name__ == '__main__':
main()
Assuming you follow the comment in the code and make sure you do not have cached_property installed within the environment you are running pylint in, you'll get the following in the errors:
$ pylint module.py
************* Module module
...
module.py:15:8: W0125: Using a conditional statement with a constant value (using-constant-test)
...
This is true even if you add cached_property.cached_property
to your pylintrc's [BASIC]
property-classes
list.
It appears that property-classes
is not used for the using-constant-test
error check, only some other naming related ones. We should have functions or methods defined with a decorator that appears in property-classes
not fail this check.
I'm not familiar enough with the code to understand where the logic that leads to a built-in property declaration working while this one does not.