summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2020-05-05 08:45:09 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2020-05-05 09:52:38 +0200
commit61e0e6b65476f083960ce5563745f337fb2454be (patch)
tree45139dcb68ae5ee08f41f9b06e3d10c81465fd8b
parente6c9ef55bcd962366685a0d8f511d8567bddb78c (diff)
downloadpylint-git-61e0e6b65476f083960ce5563745f337fb2454be.tar.gz
Address the super violations in the codebase
-rw-r--r--pylint/checkers/refactoring.py13
-rw-r--r--tests/functional/a/access_to_protected_members.py2
-rw-r--r--tests/functional/a/arguments_differ.py12
-rw-r--r--tests/functional/a/assigning_non_slot.py2
-rw-r--r--tests/functional/d/deprecated_methods_py3.py2
-rw-r--r--tests/functional/d/deprecated_methods_py38.py2
-rw-r--r--tests/functional/i/init_not_called.py4
-rw-r--r--tests/functional/m/member_checks.py4
-rw-r--r--tests/functional/m/member_checks_hints.py2
-rw-r--r--tests/functional/m/member_checks_no_hints.py2
-rw-r--r--tests/functional/m/method_hidden.py2
-rw-r--r--tests/functional/n/name_styles.py2
-rw-r--r--tests/functional/r/regression_property_no_member_844.py2
-rw-r--r--tests/functional/s/super_checks.py2
-rw-r--r--tests/functional/s/super_with_arguments.py5
-rw-r--r--tests/functional/u/useless_super_delegation.py12
-rw-r--r--tests/functional/u/useless_super_delegation_py3.py6
-rw-r--r--tests/functional/u/useless_super_delegation_py35.py4
18 files changed, 44 insertions, 36 deletions
diff --git a/pylint/checkers/refactoring.py b/pylint/checkers/refactoring.py
index fbef4ded8..72153269b 100644
--- a/pylint/checkers/refactoring.py
+++ b/pylint/checkers/refactoring.py
@@ -751,15 +751,18 @@ class RefactoringChecker(checkers.BaseTokenChecker):
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
+
+ # pylint: disable=too-many-boolean-expressions
if (
- not isinstance(node.args[1], astroid.Name)
+ len(node.args) != 2
+ or not isinstance(node.args[1], astroid.Name)
+ or node.args[1].name != "self"
+ or not isinstance(node.args[0], astroid.Name)
+ or 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):
diff --git a/tests/functional/a/access_to_protected_members.py b/tests/functional/a/access_to_protected_members.py
index a88dee82b..737d8b9d6 100644
--- a/tests/functional/a/access_to_protected_members.py
+++ b/tests/functional/a/access_to_protected_members.py
@@ -33,7 +33,7 @@ class Subclass(MyClass):
def __init__(self):
MyClass._protected = 5
- super(Subclass, self)._private_method()
+ super()._private_method()
INST = Subclass()
INST.attr = 1
diff --git a/tests/functional/a/arguments_differ.py b/tests/functional/a/arguments_differ.py
index ebe142cad..eda0c326f 100644
--- a/tests/functional/a/arguments_differ.py
+++ b/tests/functional/a/arguments_differ.py
@@ -93,7 +93,7 @@ class Sub(Super):
# pylint: disable=unused-argument
def __init__(self, arg):
- super(Sub, self).__init__()
+ super().__init__()
def __private(self, arg):
pass
@@ -142,7 +142,7 @@ class PropertySetter(Property):
class StaticmethodChild2(Staticmethod):
def func(self, data):
- super(StaticmethodChild2, self).func(data)
+ super().func(data)
class SuperClass(object):
@@ -158,7 +158,7 @@ class MyClass(SuperClass):
"""
Acceptable use of vararg in subclass because it does not violate LSP.
"""
- super(MyClass, self).impl(*args, **kwargs)
+ super().impl(*args, **kwargs)
class FirstHasArgs(object):
@@ -185,7 +185,7 @@ class PositionalChild(Positional):
"""
Acceptable use of vararg in subclass because it does not violate LSP.
"""
- super(PositionalChild, self).test(args[0], args[1])
+ super().test(args[0], args[1])
class Mixed(object):
@@ -199,7 +199,7 @@ class MixedChild1(Mixed):
"""
Acceptable use of vararg in subclass because it does not violate LSP.
"""
- super(MixedChild1, self).mixed(first, *args, **kwargs)
+ super().mixed(first, *args, **kwargs)
class MixedChild2(Mixed):
@@ -208,7 +208,7 @@ class MixedChild2(Mixed):
"""
Acceptable use of vararg in subclass because it does not violate LSP.
"""
- super(MixedChild2, self).mixed(first, *args, third, **kwargs)
+ super().mixed(first, *args, third, **kwargs)
class HasSpecialMethod(object):
diff --git a/tests/functional/a/assigning_non_slot.py b/tests/functional/a/assigning_non_slot.py
index 6fd299f37..600a2d5a2 100644
--- a/tests/functional/a/assigning_non_slot.py
+++ b/tests/functional/a/assigning_non_slot.py
@@ -34,7 +34,7 @@ class Bad3(Bad):
self.component = 42
self.member = 24
self.missing = 42 # [assigning-non-slot]
- super(Bad3, self).__init__()
+ super().__init__()
class Good(Empty):
""" missing not in slots, but Empty doesn't
diff --git a/tests/functional/d/deprecated_methods_py3.py b/tests/functional/d/deprecated_methods_py3.py
index d390c8d79..80428c79f 100644
--- a/tests/functional/d/deprecated_methods_py3.py
+++ b/tests/functional/d/deprecated_methods_py3.py
@@ -32,7 +32,7 @@ class SuperCrash(unittest.TestCase):
def __init__(self):
# should not crash.
- super(SuperCrash, self)()
+ super()()
xml.etree.ElementTree.iterparse(None)
diff --git a/tests/functional/d/deprecated_methods_py38.py b/tests/functional/d/deprecated_methods_py38.py
index 4ca5e5197..57047f926 100644
--- a/tests/functional/d/deprecated_methods_py38.py
+++ b/tests/functional/d/deprecated_methods_py38.py
@@ -27,7 +27,7 @@ class SuperCrash(unittest.TestCase):
def __init__(self):
# should not crash.
- super(SuperCrash, self)()
+ super()()
xml.etree.ElementTree.iterparse(None)
diff --git a/tests/functional/i/init_not_called.py b/tests/functional/i/init_not_called.py
index 0e5aacbea..9c9d24dae 100644
--- a/tests/functional/i/init_not_called.py
+++ b/tests/functional/i/init_not_called.py
@@ -28,13 +28,13 @@ class ZZZZ(AAAA, BBBB, CCCC):
class NewStyleA(object):
"""new style class"""
def __init__(self):
- super(NewStyleA, self).__init__()
+ super().__init__()
print('init', self)
class NewStyleB(NewStyleA):
"""derived new style class"""
def __init__(self):
- super(NewStyleB, self).__init__()
+ super().__init__()
class NoInit(object):
"""No __init__ defined"""
diff --git a/tests/functional/m/member_checks.py b/tests/functional/m/member_checks.py
index ad7793fd5..8559926c0 100644
--- a/tests/functional/m/member_checks.py
+++ b/tests/functional/m/member_checks.py
@@ -62,7 +62,7 @@ class Client(object):
none = None
print(none.whatever)
# No misssing in the parents.
- super(Client, self).misssing() # [no-member]
+ super().misssing() # [no-member]
class Mixin(object):
@@ -129,7 +129,7 @@ except AttributeError:
class SuperChecks(str, str): # pylint: disable=duplicate-bases
"""Don't fail when the MRO is invalid."""
def test(self):
- super(SuperChecks, self).lalala()
+ super().lalala()
type(Client()).ala # [no-member]
type({}).bala # [no-member]
diff --git a/tests/functional/m/member_checks_hints.py b/tests/functional/m/member_checks_hints.py
index 407c522b5..3925f4741 100644
--- a/tests/functional/m/member_checks_hints.py
+++ b/tests/functional/m/member_checks_hints.py
@@ -16,7 +16,7 @@ class Parent(object):
class Child(Parent):
def __init__(self):
- super(Child, self).__init__()
+ super().__init__()
self._similar # [no-member]
self._really_similar # [no-member]
diff --git a/tests/functional/m/member_checks_no_hints.py b/tests/functional/m/member_checks_no_hints.py
index 407c522b5..3925f4741 100644
--- a/tests/functional/m/member_checks_no_hints.py
+++ b/tests/functional/m/member_checks_no_hints.py
@@ -16,7 +16,7 @@ class Parent(object):
class Child(Parent):
def __init__(self):
- super(Child, self).__init__()
+ super().__init__()
self._similar # [no-member]
self._really_similar # [no-member]
diff --git a/tests/functional/m/method_hidden.py b/tests/functional/m/method_hidden.py
index 7131ba21a..47031d8d0 100644
--- a/tests/functional/m/method_hidden.py
+++ b/tests/functional/m/method_hidden.py
@@ -87,6 +87,6 @@ except ImportError:
class JsonEncoder(js.JSONEncoder):
- # pylint: disable=useless-super-delegation
+ # pylint: disable=useless-super-delegation,super-with-arguments
def default(self, o):
return super(JsonEncoder, self).default(o)
diff --git a/tests/functional/n/name_styles.py b/tests/functional/n/name_styles.py
index be526e68d..6a3e9015a 100644
--- a/tests/functional/n/name_styles.py
+++ b/tests/functional/n/name_styles.py
@@ -59,7 +59,7 @@ class DerivedFromCorrect(CorrectClassName):
zz = 'Now a good class attribute'
def __init__(self):
- super(DerivedFromCorrect, self).__init__()
+ super().__init__()
self._Bad_AtTR_name = None # Ignored
def BadMethodName(self):
diff --git a/tests/functional/r/regression_property_no_member_844.py b/tests/functional/r/regression_property_no_member_844.py
index 2c919fe2f..759b7bfe3 100644
--- a/tests/functional/r/regression_property_no_member_844.py
+++ b/tests/functional/r/regression_property_no_member_844.py
@@ -12,7 +12,7 @@ class Parent:
class Child(Parent):
@Parent.thing.getter
def thing(self):
- return super(Child, self).thing + '!'
+ return super().thing + '!'
print(Child().thing)
diff --git a/tests/functional/s/super_checks.py b/tests/functional/s/super_checks.py
index 241531b37..3f132dff1 100644
--- a/tests/functional/s/super_checks.py
+++ b/tests/functional/s/super_checks.py
@@ -1,6 +1,6 @@
# pylint: disable=too-few-public-methods,import-error, no-absolute-import,missing-docstring, useless-object-inheritance
# pylint: disable=useless-super-delegation,wrong-import-position,invalid-name, wrong-import-order
-
+# pylint: disable=super-with-arguments
from unknown import Missing
class Aaaa:
diff --git a/tests/functional/s/super_with_arguments.py b/tests/functional/s/super_with_arguments.py
index 8ad53ee64..ea8c0e4f1 100644
--- a/tests/functional/s/super_with_arguments.py
+++ b/tests/functional/s/super_with_arguments.py
@@ -20,3 +20,8 @@ class Qux(Foo):
class NotSuperCall(Foo):
def __init__(self):
super.test(Bar, self).__init__()
+
+
+class InvalidSuperCall(Foo):
+ def __init__(self):
+ super(InvalidSuperCall.__class__, self).__init__()
diff --git a/tests/functional/u/useless_super_delegation.py b/tests/functional/u/useless_super_delegation.py
index e6cf8680e..5cf435b96 100644
--- a/tests/functional/u/useless_super_delegation.py
+++ b/tests/functional/u/useless_super_delegation.py
@@ -1,7 +1,7 @@
# pylint: disable=missing-docstring, no-member, no-self-use, bad-super-call
# pylint: disable=too-few-public-methods, unused-argument, invalid-name, too-many-public-methods
# pylint: disable=line-too-long, useless-object-inheritance, arguments-out-of-order
-
+# pylint: disable=super-with-arguments
def not_a_method(param, param2):
return super(None, None).not_a_method(param, param2)
@@ -50,16 +50,16 @@ class Base(SuperBase):
pass
def with_default_arg_ter(self, first, default_arg="has_been_changed"):
- super(Base, self).with_default_arg_ter(first, default_arg)
+ super().with_default_arg_ter(first, default_arg)
def with_default_arg_quad(self, first, default_arg="has_been_changed"):
- super(Base, self).with_default_arg_quad(first, default_arg)
+ super().with_default_arg_quad(first, default_arg)
class NotUselessSuper(Base):
def multiple_statements(self):
first = 42 * 24
- return super(NotUselessSuper, self).multiple_statements() + first
+ return super().multiple_statements() + first
def not_a_call(self):
return 1 + 2
@@ -68,7 +68,7 @@ class NotUselessSuper(Base):
return type(self).__class__
def not_super_attribute_access(self):
- return super(NotUselessSuper, self)
+ return super()
def invalid_super_call(self):
return super(NotUselessSuper, 1).invalid_super_call()
@@ -77,7 +77,7 @@ class NotUselessSuper(Base):
return super(2, 3, 4, 5).other_invalid_super_call()
def different_name(self):
- return super(NotUselessSuper, self).something()
+ return super().something()
def different_super_mro_pointer(self):
return super(Base, self).different_super_mro_pointer()
diff --git a/tests/functional/u/useless_super_delegation_py3.py b/tests/functional/u/useless_super_delegation_py3.py
index 09bc25b4c..b32ced873 100644
--- a/tests/functional/u/useless_super_delegation_py3.py
+++ b/tests/functional/u/useless_super_delegation_py3.py
@@ -4,10 +4,10 @@
class NotUselessSuper(object):
def not_passing_keyword_only(self, first, *, second):
- return super(NotUselessSuper, self).not_passing_keyword_only(first)
+ return super().not_passing_keyword_only(first)
def passing_keyword_only_with_modifications(self, first, *, second):
- return super(NotUselessSuper, self).passing_keyword_only_with_modifications(
+ return super().passing_keyword_only_with_modifications(
first, second + 1)
@@ -19,7 +19,7 @@ class AlsoNotUselessSuper(NotUselessSuper):
class UselessSuper(object):
def useless(self, *, first): # [useless-super-delegation]
- super(UselessSuper, self).useless(first=first)
+ super().useless(first=first)
class Egg():
diff --git a/tests/functional/u/useless_super_delegation_py35.py b/tests/functional/u/useless_super_delegation_py35.py
index ffc3c6c74..16030f8a4 100644
--- a/tests/functional/u/useless_super_delegation_py35.py
+++ b/tests/functional/u/useless_super_delegation_py35.py
@@ -3,10 +3,10 @@
class NotUselessSuper(object):
def not_passing_all_params(self, first, *args, second=None, **kwargs):
- return super(NotUselessSuper, self).not_passing_all_params(*args, second, **kwargs)
+ return super().not_passing_all_params(*args, second, **kwargs)
class UselessSuper(object):
def useless(self, first, *, second=None, **kwargs): # [useless-super-delegation]
- return super(UselessSuper, self).useless(first, second=second, **kwargs)
+ return super().useless(first, second=second, **kwargs)