Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pylint can't see parent methods through Generic inheritance #4080

Closed
jolaf opened this issue Feb 9, 2021 · 2 comments
Closed

pylint can't see parent methods through Generic inheritance #4080

jolaf opened this issue Feb 9, 2021 · 2 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code inference

Comments

@jolaf
Copy link

jolaf commented Feb 9, 2021

The following code:

from typing import cast, Generic, TypeVar

class A():
    data = 'OK'

    def getValue(self) -> str:
        return self.data

class B(A):
    pass
class C(B):
    pass

print('C:', C().getValue())

T = TypeVar('T')

class AG(Generic[T]):
    data = cast(T, 'OK')

    def getValue(self) -> T:
        return self.data

class BG(AG[T]):
    pass
class CG(BG[str]):
    pass

print('CG:', CG().getValue())

produces the following ouput:

$ python3 test.py
C: OK
CG: OK

$ mypy test.py
Success: no issues found in 1 source file

$ pylint test.py
************* Module test
test.py:29: [E1101(no-member), ] Instance of 'CG' has no 'getValue' member
------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 5.50/10, +2.00)

$ pylint --version
pylint 2.6.0
astroid 2.4.2
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0]

Note the AG-BG-CG class hierarchy is identical to A-B-C class hierarchy except it uses Generics.
And no-member is reported in generic case while non-generic case is fine.

@jolaf jolaf changed the title pylint cant's ee parent methods through Generic inheritance pylint can't see parent methods through Generic inheritance Feb 9, 2021
@PCManticore PCManticore added False Positive 🦟 A message is emitted but nothing is wrong with the code inference labels Feb 16, 2021
@hippo91
Copy link
Contributor

hippo91 commented Apr 9, 2021

@jolaf thanks for the report. I can reproduce it with this smaller snippet:

#pylint: disable=missing-module-docstring, invalid-name
#pylint: disable=missing-class-docstring, missing-function-docstring
#pylint: disable=too-few-public-methods
from typing import Generic, TypeVar

T = TypeVar('T')

class AG(Generic[T]):
    data = "my_data"

    def getValue(self) -> T:
        return self.data

class BG(AG[T]):
    pass
class CG(BG[str]):
    pass

print('BG:', BG().getValue())
print('CG:', CG().getValue())

@hippo91
Copy link
Contributor

hippo91 commented Apr 9, 2021

@jolaf i will close this issue as it seems to be a duplicate of #3131.
By the way this issue should be fixed as soon as pylint-dev/astroid#927 will be merged into master.

@hippo91 hippo91 closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code inference
Projects
None yet
Development

No branches or pull requests

3 participants