Skip to content

Commit

Permalink
Deprecate rec argument to find_argname()
Browse files Browse the repository at this point in the history
Follow-up to
3db2bdd.
  • Loading branch information
jacobtylerwalls committed Jun 19, 2023
1 parent 3db2bdd commit 1167d50
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import itertools
import sys
import typing
import warnings
from collections.abc import Generator, Iterable, Iterator, Mapping
from functools import cached_property, lru_cache
from typing import (
Expand Down Expand Up @@ -506,6 +507,8 @@ def _get_name_nodes(self):
yield from child_node._get_name_nodes()


DEPRECATED_ARGUMENT_DEFAULT = object()

class Arguments(_base_nodes.AssignTypeNode):
"""Class representing an :class:`ast.arguments` node.
Expand Down Expand Up @@ -836,26 +839,28 @@ def is_argument(self, name) -> bool:
if name == self.kwarg:
return True
return (
self.find_argname(name, rec=True)[1] is not None
self.find_argname(name)[1] is not None
or self.kwonlyargs
and _find_arg(name, self.kwonlyargs, rec=True)[1] is not None
and _find_arg(name, self.kwonlyargs)[1] is not None
)

def find_argname(self, argname, rec=False):
def find_argname(self, argname, rec=DEPRECATED_ARGUMENT_DEFAULT):
"""Get the index and :class:`AssignName` node for given name.
:param argname: The name of the argument to search for.
:type argname: str
:param rec: Whether or not to include arguments in unpacked tuples
in the search.
:type rec: bool
:returns: The index and node for the argument.
:rtype: tuple(str or None, AssignName or None)
"""
if rec is not DEPRECATED_ARGUMENT_DEFAULT:
warnings.warn(
'The rec argument will be removed in a future version.',
DeprecationWarning,
stacklevel=2
)
if self.arguments:
return _find_arg(argname, self.arguments, rec)
return _find_arg(argname, self.arguments)
return None, None

def get_children(self):
Expand Down Expand Up @@ -890,14 +895,9 @@ def get_children(self):
yield elt


def _find_arg(argname, args, rec=False):
def _find_arg(argname, args):
for i, arg in enumerate(args):
if isinstance(arg, Tuple):
if rec:
found = _find_arg(argname, arg.elts)
if found[0] is not None:
return found
elif arg.name == argname:
if arg.name == argname:
return i, arg
return None, None

Expand Down

0 comments on commit 1167d50

Please sign in to comment.