logilab-astng #3531 Type inference on factory classmethod [resolved]

Maarten ter Huurne posted

class Super(object):
      @classmethod
      def instance(cls):
              return cls()

class Sub(Super):
      def method(self):
              print 'method called'

Sub.instance().method()

It prints:

E1101: 10: Instance of 'Super' has no 'method' member

The return type of "Sub.instance()" is "Sub", not "Super", so the method call is valid, as you can see when you run this program.

So it seems that ASTNG infers the wrong type: "cls" is the class on which the class method is called, which is not necessarily the class in which it is defined.

prioritynormal
typebug
done in0.17.0
load1.000
load left0.000
closed by<not specified>