Pylint: no-member false positive when using @classmethod constructors

Created on 6 Sep 2019  路  1Comment  路  Source: PyCQA/pylint

Steps to reproduce

Given a sample snippet like this:

class Bar:
    @classmethod
    def from_xyz(cls):
        return cls()

class Foo(Bar):
    @classmethod
    def from_xyz(cls):
        return super(Foo, cls).from_xyz()
    def Baz(self):
        print("Hello World!")


x = Foo.from_xyz()
x.Baz()

Current behavior

pylint will print the error:
lint.py:15:0: E1101: Instance of 'Bar' has no 'Baz' member (no-member)

Expected behavior

pylint will either recognize that:

  1. The result of calling from_xyz is of type Foo (and has a Baz member), or
  2. The result of cls() is indeterminate and checking members is not possible.

and as a result, will not print a false positive.

pylint --version output

pylint 2.3.1
astroid 2.2.5
Python 3.7.4 (default, Jul 9 2019, 16:32:37)
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]

bug topic-inference

Most helpful comment

Yeah, right now pylint emits the error as it cannot constrain the result of from_xyz to Foo. Definitely a bug that's worth fixing.

>All comments

Yeah, right now pylint emits the error as it cannot constrain the result of from_xyz to Foo. Definitely a bug that's worth fixing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PCManticore picture PCManticore  路  3Comments

DevynCJohnson picture DevynCJohnson  路  3Comments

PCManticore picture PCManticore  路  3Comments

jrial picture jrial  路  3Comments

elirnm picture elirnm  路  3Comments