I've run into the following issue with Pylint:
Given the following minimal example:
#tpack/__init__.py
class C:
@property
def ans(self):
return 42
def f(c):
return C.ans.fget(c)
Pylint produces the following error:
>pylint -d missing-docstring -d invalid-name -d too-few-public-methods tpack
************* Module tpack
tpack\__init__.py:7:11: E1101: Method 'ans' has no 'fget' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Pylint version:
>pylint --version
pylint 2.1.1
astroid 2.0.4
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)]
Is this a known issue with Pylint?
There seems to be some confusion about the use of this piece of code.
Here's an example:
>python
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from tpack import *
>>> c = C()
>>> f(c)
42
When accessing a property through the class one acquires the actual property object that the decorator generated. Through this one can access the property object's member functions. fgets
is the getter. One just has to pass an object of type C
to it, and the property is returned.
Well all the comments and the answers do make sense in the fact that instance methods should only be called on objects and not on classes. But, here since the method 'ans' is using the @property decorator, calling 'ans' on the class returns a property object. So, doing
print(C.ans)
prints
<property object at 0x000001A819E55CC8>
and
c = C()
print(c.ans)
prints
42
So your code is correct. Maybe not Pythonic ideally. But, I have tested your code and it runs just fine.
So, yeah it's probably an issue with Pylint. I don't have much insights on Pylint. So can't help you there :(