Question

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)?

Was it helpful?

Solution 2

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.

OTHER TIPS

According to this list 'Missing argument to super()' has code E1004: .If you want to disable only one type of warning you can add this line at the beginning of the file:

# pylint: disable=E1004

Or you can try calling super() like this:

class B(A):
  def __init__(self):
    super(B, self).__init__()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top