Have Pylint (1.6.4) evaluate the following snippet:
class prop(object):
def __init__(self, fn):
self.value = 5
class my_class(object):
@prop
def my_property(self):
pass
print(my_class().my_property.value)
Pylint returns the following, even with prop added to property_classes:
E: 10, 6: Method 'my_property' has no 'value' member (no-member)
No no-member errors. A decorated function should not be assumed to be a function.
pylint --version output No config file found, using default configuration
pylint 1.6.4,
astroid 1.4.8
Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602]
I've run into a similar issue with value injection on our unit tests. The following snippet runs without issue under pytest, but throws a no-member error under pylint.
from unittest import TestCase
def with_value(Cls):
Cls_setUp = Cls.setUp
def _setUp(self):
self.value = 5
self.addCleanup(delattr, self, 'value')
Cls_setUp(self)
Cls.setUp = _setUp
return Cls
@with_value
class TestValue(TestCase):
def test_value(self):
value = self.value
self.assertEqual(value, 5)
pylint 1.6.4,
astroid 1.4.8
Python 2.7.9 (default, Sep 26 2016, 12:51:32)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
Is this a duplicate of #1061 ?
Bug still bites in 2019. My case is similar, I believe:
def _experiment(name):
def __experiment(fn):
fn.experiment_name = name
return fn
return __experiment
class Librunner():
...
@_experiment('sequential_freerun')
def sequentialFreerun(self, some_parameter):
...
lib = Librunner()
experiments = [
lib.sequentialFreerun
]
runFn = experiments[0]
print(runFn.experiment_name)
Error: Method 'sequentialFreerun' has no 'experiment_name' member
pylint 2.3.1
astroid 2.2.5
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
Most helpful comment
I've run into a similar issue with value injection on our unit tests. The following snippet runs without issue under pytest, but throws a
no-membererror under pylint.pylint --version