diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-18 17:44:43 +0300 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-18 17:44:43 +0300 |
commit | a80c61921d59b919be50612f2fa9139d4e24244a (patch) | |
tree | ce900cde918a3a3725e3e50acfef36963e80585c | |
parent | bd5a11987fc9d9145a1414db635c803818ddd5c9 (diff) | |
parent | 3df1fb9ee598eec589c988b7790cf44b031341f2 (diff) | |
download | pylint-a80c61921d59b919be50612f2fa9139d4e24244a.tar.gz |
Merged in dmand/pylint/fix-667 (pull request #287)
Make `no-self-use` checker not throw a warning if method has a `super()` call.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | pylint/checkers/classes.py | 11 | ||||
-rw-r--r-- | pylint/test/functional/no_self_use_py3.py | 12 | ||||
-rw-r--r-- | pylint/test/functional/no_self_use_py3.rc | 2 | ||||
-rw-r--r-- | pylint/test/functional/no_self_use_py3.txt | 1 |
5 files changed, 29 insertions, 1 deletions
@@ -2,6 +2,10 @@ ChangeLog for Pylint -------------------- -- + * Make 'no-self-use' checker not emit a warning if there is a 'super()' + call inside the method. + Closes issue #667. + * Add checker to identify multiple imports on one line. Closes issue #598. diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index 0fc0fae..c39b971 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -140,6 +140,14 @@ def _is_attribute_property(name, klass): return True return False +def _has_bare_super_call(fundef_node): + for call in fundef_node.nodes_of_class(astroid.Call): + func = call.func + if (isinstance(func, astroid.Name) and + func.name == 'super' and + not call.args): + return True + return False MSGS = { 'F0202': ('Unable to check methods signature (%s / %s)', @@ -545,7 +553,8 @@ a metaclass class method.'} and not node.name in PYMETHODS and not (node.is_abstract() or overrides_a_method(class_node, node.name) or - decorated_with_property(node))): + decorated_with_property(node) or + (six.PY3 and _has_bare_super_call(node)))): self.add_message('no-self-use', node=node) def visit_attribute(self, node): diff --git a/pylint/test/functional/no_self_use_py3.py b/pylint/test/functional/no_self_use_py3.py new file mode 100644 index 0000000..f401508 --- /dev/null +++ b/pylint/test/functional/no_self_use_py3.py @@ -0,0 +1,12 @@ +# pylint: disable=missing-docstring,no-init,unused-argument,invalid-name,too-few-public-methods + +class A: + def __init__(self): + self.store = {} + + def get(self, key, default=None): + return self.store.get(key, default) + +class B(A): + def get_memo(self, obj): + return super().get(obj) diff --git a/pylint/test/functional/no_self_use_py3.rc b/pylint/test/functional/no_self_use_py3.rc new file mode 100644 index 0000000..a2ab06c --- /dev/null +++ b/pylint/test/functional/no_self_use_py3.rc @@ -0,0 +1,2 @@ +[testoptions] +min_pyver=3.0
\ No newline at end of file diff --git a/pylint/test/functional/no_self_use_py3.txt b/pylint/test/functional/no_self_use_py3.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pylint/test/functional/no_self_use_py3.txt @@ -0,0 +1 @@ + |