Skip to content

Commit

Permalink
Fix a false positive for invalid-getnewargs-ex-returned when the …
Browse files Browse the repository at this point in the history
…tuple or dict has been assigned to a name. (#10209)
  • Loading branch information
mbyrnepr2 authored Jan 30, 2025
1 parent b2598fa commit 8138620
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10208.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a false positive for ``invalid-getnewargs-ex-returned`` when the tuple or dict has been assigned to a name.

Closes #10208
2 changes: 1 addition & 1 deletion pylint/checkers/classes/special_methods_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def _check_getnewargs_ex(
(inferred.elts[0], self._is_tuple),
(inferred.elts[1], self._is_dict),
):
if isinstance(arg, nodes.Call):
if isinstance(arg, (nodes.Call, nodes.Name)):
arg = safe_infer(arg)

if arg and not isinstance(arg, util.UninferableBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ class ThirdGoodGetNewArgsEx:
"""GetNewArgsEx through the metaclass."""


class FourthGoodGetNewArgsEx:
"""Test that `args` and `kwargs` (`Name` nodes) are inferred as tuples.
https://github.com/pylint-dev/pylint/issues/10208
"""
def __init__(self, boo, far, *, hoo, haha):
self._foo = boo
self._bar = far
self._hoo = hoo
self._haha = haha

def __getnewargs_ex__(self):
args = (self._foo, self._bar)
kwargs = {'hoo': self._hoo,
'haha': self._haha}
return args, kwargs


class FirstBadGetNewArgsEx:
""" __getnewargs_ex__ returns an integer """

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

0 comments on commit 8138620

Please sign in to comment.