-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeinference
Description
Before I begin, I just want to say Pylint is awesome. When I update from Python 3.6.5 to Python 3.8.2, it helped me figure out which built-in libraries had their API's changed (ex: time.clock
's removal).
However, when I updated from 3.6.5 to 3.8.2, I discovered a Pylint bug as well. I would like to report a false positive on E1101, no-member
.
I have found that when using a certain combination of:
typing.Generic
property
- Two subclassing's
That pylint erroneously reports no-member
.
Steps to reproduce
In the below code, you can see:
base_property
is aproperty
BaseClass
is a subclass ofGeneric
base_property
is type hinted with aTypeVar
BaseClass
is subclassed twice -->GrandchildClass
- One subclassing, and the false positive doesn't happen
#!/usr/bin/env python3
"""Testing pylint raising of no-member."""
from typing import TypeVar, Generic
TFloatInt = TypeVar("TFloatInt", int, float)
class BaseClass(Generic[TFloatInt]):
@property
def base_property(self) -> TFloatInt:
return 1
class ChildClass(BaseClass[TFloatInt]):
"""A docstring."""
class GrandchildClass(BaseClass[int]):
def grandchild_method(self) -> int:
return self.base_property # E1101: Instance of 'GrandchildClass' has no 'base_property' member (no-member)
if __name__ == "__main__":
grandchild = GrandchildClass()
print(grandchild.grandchild_method())
Pylint output:
/path/to/my_module.py:27:15: E1101: Instance of 'GrandchildClass' has no 'base_property' member (no-member)
At runtime, this code works fine.
Expected behavior
I believe the above code sample should not raise a no-member
.
Note: this behavior depends on the Python version:
- Does not happen for Python 3.6.5
- Does happen for Python 3.8.2
pylint --version output
pylint 2.5.3
astroid 2.4.2
Python 3.8.2 (default, Jun 11 2020, 17:42:03)
[Clang 10.0.1 (clang-1001.0.46.4)]
NeilGirdhar
Metadata
Metadata
Assignees
Labels
False Positive 🦟A message is emitted but nothing is wrong with the codeA message is emitted but nothing is wrong with the codeinference