Search code examples
pythoninheritancepython-3.xconstructorpylint

How to avoid Pylint warnings for constructor of inherited class in Python 3?


In Python 3, I have the following code:

class A:
    def __init__(self):
        pass

class B(A):
    def __init__(self):
        super().__init__()

This yields the Pylint warning:

  • Old-style class defined. (old-style-class)
  • Use of super on an old style class (super-on-old-class)

In my understanding, in Python 3 there does not exist an old-style class anymore and this code is OK.

Even if I explicitly use new-style classes with this code

class A(object):
    def __init__(self):
        pass

class B(A):
    def __init__(self):
        super().__init__()

I get Pylint warning because of the different syntax to call the parent constructor in Python 3:

  • Missing argument to super() (missing-super-argument)

So, how can I tell Pylint that I want to check Python 3 code to avoid these messages (without disabling the Pylint check)?


Solution

  • This is due to a bug in astroid, which wasn't considering all classes as new style w/ python 3 before https://bitbucket.org/logilab/astroid/commits/6869fb2acb9f58f0ba2197c6e9008989d85ca1ca

    That should be released shortly.