Skip to content

Commit 698a376

Browse files
Deprecate rec argument to find_argname() (#2217)
Follow-up to 3db2bdd.
1 parent 842548d commit 698a376

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

astroid/nodes/node_classes.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import itertools
1111
import sys
1212
import typing
13+
import warnings
1314
from collections.abc import Generator, Iterable, Iterator, Mapping
1415
from functools import cached_property, lru_cache
1516
from typing import (
@@ -506,6 +507,9 @@ def _get_name_nodes(self):
506507
yield from child_node._get_name_nodes()
507508

508509

510+
DEPRECATED_ARGUMENT_DEFAULT = object()
511+
512+
509513
class Arguments(_base_nodes.AssignTypeNode):
510514
"""Class representing an :class:`ast.arguments` node.
511515
@@ -836,26 +840,28 @@ def is_argument(self, name) -> bool:
836840
if name == self.kwarg:
837841
return True
838842
return (
839-
self.find_argname(name, rec=True)[1] is not None
843+
self.find_argname(name)[1] is not None
840844
or self.kwonlyargs
841-
and _find_arg(name, self.kwonlyargs, rec=True)[1] is not None
845+
and _find_arg(name, self.kwonlyargs)[1] is not None
842846
)
843847

844-
def find_argname(self, argname, rec=False):
848+
def find_argname(self, argname, rec=DEPRECATED_ARGUMENT_DEFAULT):
845849
"""Get the index and :class:`AssignName` node for given name.
846850
847851
:param argname: The name of the argument to search for.
848852
:type argname: str
849853
850-
:param rec: Whether or not to include arguments in unpacked tuples
851-
in the search.
852-
:type rec: bool
853-
854854
:returns: The index and node for the argument.
855855
:rtype: tuple(str or None, AssignName or None)
856856
"""
857+
if rec is not DEPRECATED_ARGUMENT_DEFAULT: # pragma: no cover
858+
warnings.warn(
859+
"The rec argument will be removed in astroid 3.1.",
860+
DeprecationWarning,
861+
stacklevel=2,
862+
)
857863
if self.arguments:
858-
return _find_arg(argname, self.arguments, rec)
864+
return _find_arg(argname, self.arguments)
859865
return None, None
860866

861867
def get_children(self):
@@ -890,14 +896,9 @@ def get_children(self):
890896
yield elt
891897

892898

893-
def _find_arg(argname, args, rec=False):
899+
def _find_arg(argname, args):
894900
for i, arg in enumerate(args):
895-
if isinstance(arg, Tuple):
896-
if rec:
897-
found = _find_arg(argname, arg.elts)
898-
if found[0] is not None:
899-
return found
900-
elif arg.name == argname:
901+
if arg.name == argname:
901902
return i, arg
902903
return None, None
903904

0 commit comments

Comments
 (0)