Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 604
romor Avatar asked Mar 06 '14 20:03

romor


1 Answers

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__()
like image 64
skamsie Avatar answered Sep 28 '22 09:09

skamsie