Skip to content

Commit 2f6fffc

Browse files
mbyrnepr2github-actions[bot]
authored andcommitted
Fix a false positive for invalid-getnewargs-ex-returned when the tuple or dict has been assigned to a name. (#10209)
(cherry picked from commit 8138620)
1 parent c2b01c3 commit 2f6fffc

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix a false positive for ``invalid-getnewargs-ex-returned`` when the tuple or dict has been assigned to a name.
2+
3+
Closes #10208

pylint/checkers/classes/special_methods_checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def _check_getnewargs_ex(
391391
(inferred.elts[0], self._is_tuple),
392392
(inferred.elts[1], self._is_dict),
393393
):
394-
if isinstance(arg, nodes.Call):
394+
if isinstance(arg, (nodes.Call, nodes.Name)):
395395
arg = safe_infer(arg)
396396

397397
if arg and not isinstance(arg, util.UninferableBase):

tests/functional/i/invalid/invalid_getnewargs/invalid_getnewargs_ex_returned.py

+18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ class ThirdGoodGetNewArgsEx:
3030
"""GetNewArgsEx through the metaclass."""
3131

3232

33+
class FourthGoodGetNewArgsEx:
34+
"""Test that `args` and `kwargs` (`Name` nodes) are inferred as tuples.
35+
36+
https://github.com/pylint-dev/pylint/issues/10208
37+
"""
38+
def __init__(self, boo, far, *, hoo, haha):
39+
self._foo = boo
40+
self._bar = far
41+
self._hoo = hoo
42+
self._haha = haha
43+
44+
def __getnewargs_ex__(self):
45+
args = (self._foo, self._bar)
46+
kwargs = {'hoo': self._hoo,
47+
'haha': self._haha}
48+
return args, kwargs
49+
50+
3351
class FirstBadGetNewArgsEx:
3452
""" __getnewargs_ex__ returns an integer """
3553

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
invalid-getnewargs-ex-returned:36:4:36:25:FirstBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
2-
invalid-getnewargs-ex-returned:43:4:43:25:SecondBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
3-
invalid-getnewargs-ex-returned:50:4:50:25:ThirdBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
4-
invalid-getnewargs-ex-returned:57:4:57:25:FourthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
5-
invalid-getnewargs-ex-returned:64:4:64:25:FifthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
6-
invalid-getnewargs-ex-returned:71:4:71:25:SixthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
1+
invalid-getnewargs-ex-returned:54:4:54:25:FirstBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
2+
invalid-getnewargs-ex-returned:61:4:61:25:SecondBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
3+
invalid-getnewargs-ex-returned:68:4:68:25:ThirdBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
4+
invalid-getnewargs-ex-returned:75:4:75:25:FourthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
5+
invalid-getnewargs-ex-returned:82:4:82:25:FifthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED
6+
invalid-getnewargs-ex-returned:89:4:89:25:SixthBadGetNewArgsEx.__getnewargs_ex__:__getnewargs_ex__ does not return a tuple containing (tuple, dict):UNDEFINED

0 commit comments

Comments
 (0)