summaryrefslogtreecommitdiff
path: root/pylint/checkers/refactoring.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-05-05 08:25:58 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-05-05 09:52:38 +0200
commite6c9ef55bcd962366685a0d8f511d8567bddb78c (patch)
tree1529a8345140ed6095f9d5511c4a55e2c56a194e /pylint/checkers/refactoring.py
parentb170461a6c8d24fec9a7ba6f3d7dc9d9cec1dd72 (diff)
downloadpylint-git-e6c9ef55bcd962366685a0d8f511d8567bddb78c.tar.gz
Rename the new old-style super with super-with-arguments
Also move it from the Python 3 checker to the refactoring one, as it's a better fit for it.
Diffstat (limited to 'pylint/checkers/refactoring.py')
-rw-r--r--pylint/checkers/refactoring.py23
1 files changed, 23 insertions, 0 deletions
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