pylint icon indicating copy to clipboard operation
pylint copied to clipboard

no-member false positive from NewType

Open jordan-schneider opened this issue 4 years ago • 4 comments

This is a weird interaction between the typing library and pylint, so I'm not sure if this is the right place to file the bug, but here goes.

Steps to reproduce

from typing import NewType


class A:
    def __init__(self, value: int):
        self.value = value

a = A(5)
a.value  # no no-member error

B = NewType("B", A)

b = B(a)
b.value  # Instance of 'B' has no 'value' memberpylint(no-member)

Current behavior

Pylint flags a no-member error when accessing members of objects with a NewType class.

Expected behavior

Pylint flags no errors.

pylint --version output

pylint 2.4.2 astroid 2.3.1 Python 3.7.4 (default, Sep 20 2019, 11:46:08) [GCC 8.3.0]

jordan-schneider avatar Oct 04 '19 00:10 jordan-schneider

Thanks for reporting the issue. We currently do not support NewType but it's something we can add in astroid.

PCManticore avatar Oct 09 '19 12:10 PCManticore

Looks like a duplicate of #2296. Are there any plans of fixing this soon? This is a real show-stopper for pylint in projects which take typing a bit more seriously.

svenpanne avatar Feb 27 '20 07:02 svenpanne

@svenpanne Feel free to start working on this yourself. This project currently has ~500 opened issues and overburdened maintainers so your "pet" issue might not be fixed "soon". After all, the code is open source, feel free to fork the project and do whatever you want with it.

PCManticore avatar Feb 27 '20 08:02 PCManticore

Well, my proposal is simply to revert the commit mentioned in #2296, as it obviously does more harm than good...

svenpanne avatar Feb 27 '20 08:02 svenpanne