Skip to content

Commit 66ee6a6

Browse files
committed
Update unused-argument functional test
Update `unused-argument` test to include a check for the case of `__init__` and `__new__` being defined in a class but `__new__` does not use all of the argument. This is fine because `__new__` must have the same argument of `__init__`. Update with a second check in case of `__init__` being not defined in a class. Then the unused arguments check must be done on `__new__`.
1 parent 8df2263 commit 66ee6a6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/functional/u/unused/unused_argument.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,24 @@ class Descendant(Ancestor):
107107
def set_thing(self, thing, *, other=None):
108108
"""Subclass does not raise unused-argument"""
109109
self.thing = thing
110+
111+
112+
# Test that Class with both `__init__` and `__new__` don't check
113+
# on `__new__` for unused arguments
114+
115+
# pylint: disable=invalid-name
116+
117+
class TestClassWithInitAndNew:
118+
def __init__(self, argA, argB):
119+
self.argA = argA
120+
self.argB = argB
121+
122+
def __new__(cls, argA, argB):
123+
return object.__new__(cls)
124+
125+
# Test that `__new__` method is checked for unused arguments
126+
# when `__init__` is not in the Class
127+
128+
class TestClassWithOnlyNew:
129+
def __new__(cls, argA, argB): # [unused-argument, unused-argument]
130+
return object.__new__(cls)

tests/functional/u/unused/unused_argument.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ unused-argument:73:0:None:None:AAAA.selected:Unused argument 'args':INFERENCE
77
unused-argument:73:0:None:None:AAAA.selected:Unused argument 'kwargs':INFERENCE
88
unused-argument:92:23:92:26:BBBB.__init__:Unused argument 'arg':INFERENCE
99
unused-argument:103:34:103:39:Ancestor.set_thing:Unused argument 'other':INFERENCE
10+
unused-argument:129:21:129:25:TestClassWithOnlyNew.__new__:Unused argument 'argA':INFERENCE
11+
unused-argument:129:27:129:31:TestClassWithOnlyNew.__new__:Unused argument 'argB':INFERENCE

0 commit comments

Comments
 (0)