summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--doc/whatsnew/2.6.rst2
-rw-r--r--pylint/checkers/python3.py20
-rw-r--r--pylint/checkers/refactoring.py23
-rw-r--r--tests/checkers/unittest_python3.py34
-rw-r--r--tests/functional/s/super_style.txt1
-rw-r--r--tests/functional/s/super_with_arguments.py (renamed from tests/functional/s/super_style.py)7
-rw-r--r--tests/functional/s/super_with_arguments.rc (renamed from tests/functional/s/super_style.rc)2
-rw-r--r--tests/functional/s/super_with_arguments.txt1
9 files changed, 37 insertions, 62 deletions
diff --git a/ChangeLog b/ChangeLog
index b863383be..2fd40564c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,17 +8,18 @@ Release date: TBA
* bad-continuation and bad-whitespace have been removed, black or another formatter can help you with this better than Pylint
- Close #246, #289, #638, #747, #1148, #1179, #1943, #2041, #2301, #2304, #2944, #3565
+ Close #246, #289, #638, #747, #1148, #1179, #1943, #2041, #2301, #2304, #2944, #3565
* The no-space-check option has been removed. It's no longer possible to consider empty line like a `trailing-whitespace` by using clever options
- Close #1368
+ Close #1368
* mixed-indentation has been removed, it is no longer useful since TabError is included directly in python3
-* Add `old-style-super` check for flagging instances of Python 2 style super calls.
+ Close #2984 #3573
+
+* Add `super-with-arguments` check for flagging instances of Python 2 style super calls.
- Close #2984 #3573
What's New in Pylint 2.5.1?
===========================
diff --git a/doc/whatsnew/2.6.rst b/doc/whatsnew/2.6.rst
index c00053acd..5ab2028c1 100644
--- a/doc/whatsnew/2.6.rst
+++ b/doc/whatsnew/2.6.rst
@@ -13,7 +13,7 @@ Summary -- Release highlights
New checkers
============
-* Add `old-style-super` check for flagging instances of Python 2 style super calls.
+* Add `super-with-arguments` check for flagging instances of Python 2 style super calls.
Other Changes
=============
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py
index 0f5690020..f0849042c 100644
--- a/pylint/checkers/python3.py
+++ b/pylint/checkers/python3.py
@@ -598,12 +598,6 @@ class Python3Checker(checkers.BaseChecker):
"variables will be deleted outside of the "
"comprehension.",
),
- "C1601": (
- "Consider using Python 3 style super() without arguments",
- "old-style-super",
- "Emitted when calling the super builtin with the current class "
- "and instance. On Python 3 these arguments are the default.",
- ),
}
_bad_builtins = frozenset(
@@ -1245,20 +1239,6 @@ class Python3Checker(checkers.BaseChecker):
if kwarg.arg == "encoding":
self._validate_encoding(kwarg.value, node)
break
- elif node.func.name == "super":
- if len(node.args) != 2:
- return
- if (
- not isinstance(node.args[1], astroid.Name)
- or node.args[1].name != "self"
- ):
- return
- if (
- not isinstance(node.args[1], astroid.Name)
- or node.args[0].name != node.scope().parent.name
- ):
- return
- self.add_message("old-style-super", node=node)
def _validate_encoding(self, encoding, node):
if isinstance(encoding, astroid.Const):
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py
index 6fbca4d54..fbef4ded8 100644
--- a/pylint/checkers/refactoring.py
+++ b/pylint/checkers/refactoring.py
@@ -45,6 +45,7 @@ from astroid import decorators
from pylint import checkers, interfaces
from pylint import utils as lint_utils
from pylint.checkers import utils
+from pylint.checkers.utils import node_frame_class
KNOWN_INFINITE_ITERATORS = {"itertools.count"}
BUILTIN_EXIT_FUNCS = frozenset(("quit", "exit"))
@@ -309,6 +310,12 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"following a chain of ifs, all of them containing a "
"continue statement.",
),
+ "R1725": (
+ "Consider using Python 3 style super() without arguments",
+ "super-with-arguments",
+ "Emitted when calling the super() builtin with the current class "
+ "and instance. On Python 3 these arguments are the default and they can be omitted.",
+ ),
}
options = (
(
@@ -715,11 +722,13 @@ class RefactoringChecker(checkers.BaseTokenChecker):
"consider-using-dict-comprehension",
"consider-using-set-comprehension",
"consider-using-sys-exit",
+ "super-with-arguments",
)
def visit_call(self, node):
self._check_raising_stopiteration_in_generator_next_call(node)
self._check_consider_using_comprehension_constructor(node)
self._check_quit_exit_call(node)
+ self._check_super_with_arguments(node)
@staticmethod
def _has_exit_in_scope(scope):
@@ -739,6 +748,20 @@ class RefactoringChecker(checkers.BaseTokenChecker):
return
self.add_message("consider-using-sys-exit", node=node)
+ def _check_super_with_arguments(self, node):
+ if not isinstance(node.func, astroid.Name) or node.func.name != "super":
+ return
+ if len(node.args) != 2:
+ return
+ if not isinstance(node.args[1], astroid.Name) or node.args[1].name != "self":
+ return
+ if (
+ not isinstance(node.args[1], astroid.Name)
+ or node.args[0].name != node_frame_class(node).name
+ ):
+ return
+ self.add_message("super-with-arguments", node=node)
+
def _check_raising_stopiteration_in_generator_next_call(self, node):
"""Check if a StopIteration exception is raised by the call to next function
diff --git a/tests/checkers/unittest_python3.py b/tests/checkers/unittest_python3.py
index e6c5b5fe1..fdb5b26fd 100644
--- a/tests/checkers/unittest_python3.py
+++ b/tests/checkers/unittest_python3.py
@@ -1153,37 +1153,3 @@ class TestPython3Checker(testutils.CheckerTestCase):
message = testutils.Message("next-method-defined", node=node)
with self.assertAddsMessages(message):
self.checker.visit_functiondef(node)
-
- def test_old_style_super(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- def __init__():
- super(Foo, self).__init__() #@
- """
- ).func.expr
- message = testutils.Message("old-style-super", node=node)
- with self.assertAddsMessages(message):
- self.checker.visit_call(node)
-
- def test_super_non_default_args(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- def __init__():
- super(Bar, self).__init__() #@
- """
- ).func.expr
- with self.assertNoMessages():
- self.checker.visit_call(node)
-
- def test_new_style_super(self):
- node = astroid.extract_node(
- """
- class Foo(object):
- def __init__():
- super().__init__() #@
- """
- ).func.expr
- with self.assertNoMessages():
- self.checker.visit_call(node)
diff --git a/tests/functional/s/super_style.txt b/tests/functional/s/super_style.txt
deleted file mode 100644
index 50235699e..000000000
--- a/tests/functional/s/super_style.txt
+++ /dev/null
@@ -1 +0,0 @@
-old-style-super:7:Bar.__init__:Consider using Python 3 style super() without arguments
diff --git a/tests/functional/s/super_style.py b/tests/functional/s/super_with_arguments.py
index 342e67c4b..8ad53ee64 100644
--- a/tests/functional/s/super_style.py
+++ b/tests/functional/s/super_with_arguments.py
@@ -4,7 +4,7 @@ class Foo:
class Bar(Foo):
def __init__(self):
- super(Bar, self).__init__() # [old-style-super]
+ super(Bar, self).__init__() # [super-with-arguments]
class Baz(Foo):
@@ -15,3 +15,8 @@ class Baz(Foo):
class Qux(Foo):
def __init__(self):
super(Bar, self).__init__()
+
+
+class NotSuperCall(Foo):
+ def __init__(self):
+ super.test(Bar, self).__init__()
diff --git a/tests/functional/s/super_style.rc b/tests/functional/s/super_with_arguments.rc
index cfff8dab7..0e70163ee 100644
--- a/tests/functional/s/super_style.rc
+++ b/tests/functional/s/super_with_arguments.rc
@@ -1,3 +1,3 @@
[Messages Control]
disable=all
-enable=old-style-super
+enable=super-with-arguments
diff --git a/tests/functional/s/super_with_arguments.txt b/tests/functional/s/super_with_arguments.txt
new file mode 100644
index 000000000..e96cf89b3
--- /dev/null
+++ b/tests/functional/s/super_with_arguments.txt
@@ -0,0 +1 @@
+super-with-arguments:7:Bar.__init__:Consider using Python 3 style super() without arguments