Skip to content

Commit

Permalink
Add example for bad-super-call (#6166)
Browse files Browse the repository at this point in the history
Co-authored by: Vladyslav Krylasov <vladyslav.krylasov@gmail.com>
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
DudeNr33 committed Apr 3, 2022
1 parent 6718502 commit b82183b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/data/messages/b/bad-super-call/bad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Animal:
pass


class Cat(Animal):
def __init__(self):
super(Animal, self).__init__() # [bad-super-call]
4 changes: 4 additions & 0 deletions doc/data/messages/b/bad-super-call/details.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
In Python 2.7, ``super()`` has to be called with its own class and ``self`` as arguments (``super(Cat, self)``), which can
lead to a mix up of parent and child class in the code.

In Python 3 the recommended way is to call ``super()`` without arguments (see also ``super-with-arguments``).
7 changes: 7 additions & 0 deletions doc/data/messages/b/bad-super-call/good.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Animal:
pass


class Cat(Animal):
def __init__(self):
super().__init__()
1 change: 1 addition & 0 deletions doc/data/messages/b/bad-super-call/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `Documentation for super() <https://docs.python.org/3/library/functions.html#super>`_

0 comments on commit b82183b

Please sign in to comment.