Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example for bad-super-call #6166

Merged
merged 3 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Foo:
pass


class Bar(Foo):
def __init__(self):
super(Foo, self).__init__() # [bad-super-call]
DudeNr33 marked this conversation as resolved.
Show resolved Hide resolved
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 the own class and ``self`` as arguments (``super(Bar, self)``), which can
DudeNr33 marked this conversation as resolved.
Show resolved Hide resolved
lead to a mix up of parent and child class in the code.

In Python 3 the recommended way is to user ``super()`` without arguments (see also ``super-with-arguments``).
DudeNr33 marked this conversation as resolved.
Show resolved Hide resolved
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 Foo:
pass


class Bar(Foo):
def __init__(self):
super().__init__()
DudeNr33 marked this conversation as resolved.
Show resolved Hide resolved
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>`_