diff options
| author | Federico Bond <federicobond@gmail.com> | 2020-05-03 21:50:36 -0300 |
|---|---|---|
| committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2020-05-05 07:08:55 +0200 |
| commit | d4c8bcd74e37d84d0c3a7e1624e49ca6dc50ae8b (patch) | |
| tree | 44f6d5aded972240fd3141d93d27b7167a2c8f09 /pylint/checkers/python3.py | |
| parent | 3fffdf03d5a32e4a0d1b5216ea9d16dacacdaa6f (diff) | |
| download | pylint-git-d4c8bcd74e37d84d0c3a7e1624e49ca6dc50ae8b.tar.gz | |
Add new old-style-super check to flag instances of super with default arguments
Diffstat (limited to 'pylint/checkers/python3.py')
| -rw-r--r-- | pylint/checkers/python3.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/pylint/checkers/python3.py b/pylint/checkers/python3.py index 11fc0eec0..0f5690020 100644 --- a/pylint/checkers/python3.py +++ b/pylint/checkers/python3.py @@ -598,6 +598,12 @@ 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( @@ -1233,12 +1239,26 @@ class Python3Checker(checkers.BaseChecker): if not _in_iterating_context(node): checker = "{}-builtin-not-iterating".format(node.func.name) self.add_message(checker, node=node) - if node.func.name == "open" and node.keywords: + elif node.func.name == "open" and node.keywords: kwargs = node.keywords for kwarg in kwargs or []: 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): |
