Skip to content

False positive no-member when using cls to instantiate an object in super() #4241

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

Closed
yanqd0 opened this issue Mar 17, 2021 · 4 comments
Closed
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@yanqd0
Copy link

yanqd0 commented Mar 17, 2021

Steps to reproduce

Given a file a.py:

# pylint: disable=too-few-public-methods, missing-module-docstring
# pylint: disable=missing-class-docstring, missing-function-docstring
# pylint: disable=invalid-name
class A:
    a = 1

    @classmethod
    def create(cls):
        return cls()


class B(A):
    b = 2

    @classmethod
    def create(cls):
        return super().create()


b = B.create()
print(b.b)

Current behavior

Result of pylint a.py:

$ pylint a.py
************* Module a
a.py:21:6: E1101: Instance of 'A' has no 'b' member; maybe 'a'? (no-member)

Expected behavior

No error or warning.

pylint --version output

Result of pylint --version output:

pylint 2.7.2
astroid 2.5.1
Python 3.8.5 (default, Jan 27 2021, 15:41:15) 
[GCC 9.3.0]
@hippo91
Copy link
Contributor

hippo91 commented Apr 8, 2021

@yanqd0 thanks for the report.

@jacobtylerwalls
Copy link
Member

There are a lot of tickets for no-member and subclassing: #4241, #3805, #3143, #3162, and more. I haven't carefully checked to see whether they're all more or less a result of the same root cause.

@jacobtylerwalls
Copy link
Member

They probably are: see pylint-dev/astroid#457

@jacobtylerwalls
Copy link
Member

Duplicate of #981 and pylint-dev/astroid#457

@jacobtylerwalls jacobtylerwalls added the Duplicate 🐫 Duplicate of an already existing issue label Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

3 participants