Skip to content

Commit

Permalink
Add regression test for #5771 (#5908)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Mar 13, 2022
1 parent 9d46885 commit 8d57195
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Expand Up @@ -154,6 +154,12 @@ Release date: TBA
Closes #5408
Ref PyCQA/astroid#1392

* Fixed false positive for ``unused-argument`` when a method overridden in a subclass
does nothing with the value of a keyword-only argument.

Closes #5771
Ref PyCQA/astroid#1382

* The issue template for crashes is now created for crashes which were previously not covered
by this mechanism.

Expand Down
6 changes: 6 additions & 0 deletions doc/whatsnew/2.13.rst
Expand Up @@ -247,6 +247,12 @@ Other Changes
Closes #5408
Ref PyCQA/astroid#1392

* Fixed false positive for ``unused-argument`` when a method overridden in a subclass
does nothing with the value of a keyword-only argument.

Closes #5771
Ref PyCQA/astroid#1382

* Fix ``unnecessary_dict_index_lookup`` false positive when deleting a dictionary's entry.

Closes #4716
Expand Down
4 changes: 1 addition & 3 deletions pylint/checkers/variables.py
Expand Up @@ -2310,9 +2310,7 @@ def _check_is_unused(self, name, node, stmt, global_names, nonlocal_names):
if global_names and _import_name_is_global(stmt, global_names):
return

argnames = list(
itertools.chain(node.argnames(), [arg.name for arg in node.args.kwonlyargs])
)
argnames = node.argnames()
# Care about functions with unknown argument (builtins)
if name in argnames:
self._check_unused_arguments(name, node, stmt, argnames)
Expand Down
15 changes: 15 additions & 0 deletions tests/functional/u/unused/unused_argument.py
Expand Up @@ -87,3 +87,18 @@ class BBBB(object):
def __init__(self, arg): # [unused-argument]
"""Constructor with an extra parameter. Should raise a warning"""
self.spam = 1


# Regression test for https://github.com/PyCQA/pylint/issues/5771
# involving keyword-only arguments
class Ancestor:
def __init__(self):
self.thing = None

def set_thing(self, thing, *, other=None): # [unused-argument]
self.thing = thing

class Descendant(Ancestor):
def set_thing(self, thing, *, other=None):
"""Subclass does not raise unused-argument"""
self.thing = thing
1 change: 1 addition & 0 deletions tests/functional/u/unused/unused_argument.txt
Expand Up @@ -6,3 +6,4 @@ unused-argument:61:21:61:24:AAAA.method:Unused argument 'arg':INFERENCE
unused-argument:68:0:None:None:AAAA.selected:Unused argument 'args':INFERENCE
unused-argument:68:0:None:None:AAAA.selected:Unused argument 'kwargs':INFERENCE
unused-argument:87:23:87:26:BBBB.__init__:Unused argument 'arg':INFERENCE
unused-argument:98:34:98:39:Ancestor.set_thing:Unused argument 'other':INFERENCE

0 comments on commit 8d57195

Please sign in to comment.