|
10 | 10 | import itertools
|
11 | 11 | import sys
|
12 | 12 | import typing
|
| 13 | +import warnings |
13 | 14 | from collections.abc import Generator, Iterable, Iterator, Mapping
|
14 | 15 | from functools import cached_property, lru_cache
|
15 | 16 | from typing import (
|
@@ -506,6 +507,9 @@ def _get_name_nodes(self):
|
506 | 507 | yield from child_node._get_name_nodes()
|
507 | 508 |
|
508 | 509 |
|
| 510 | +DEPRECATED_ARGUMENT_DEFAULT = object() |
| 511 | + |
| 512 | + |
509 | 513 | class Arguments(_base_nodes.AssignTypeNode):
|
510 | 514 | """Class representing an :class:`ast.arguments` node.
|
511 | 515 |
|
@@ -836,26 +840,28 @@ def is_argument(self, name) -> bool:
|
836 | 840 | if name == self.kwarg:
|
837 | 841 | return True
|
838 | 842 | return (
|
839 |
| - self.find_argname(name, rec=True)[1] is not None |
| 843 | + self.find_argname(name)[1] is not None |
840 | 844 | 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 |
842 | 846 | )
|
843 | 847 |
|
844 |
| - def find_argname(self, argname, rec=False): |
| 848 | + def find_argname(self, argname, rec=DEPRECATED_ARGUMENT_DEFAULT): |
845 | 849 | """Get the index and :class:`AssignName` node for given name.
|
846 | 850 |
|
847 | 851 | :param argname: The name of the argument to search for.
|
848 | 852 | :type argname: str
|
849 | 853 |
|
850 |
| - :param rec: Whether or not to include arguments in unpacked tuples |
851 |
| - in the search. |
852 |
| - :type rec: bool |
853 |
| -
|
854 | 854 | :returns: The index and node for the argument.
|
855 | 855 | :rtype: tuple(str or None, AssignName or None)
|
856 | 856 | """
|
| 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 | + ) |
857 | 863 | if self.arguments:
|
858 |
| - return _find_arg(argname, self.arguments, rec) |
| 864 | + return _find_arg(argname, self.arguments) |
859 | 865 | return None, None
|
860 | 866 |
|
861 | 867 | def get_children(self):
|
@@ -890,14 +896,9 @@ def get_children(self):
|
890 | 896 | yield elt
|
891 | 897 |
|
892 | 898 |
|
893 |
| -def _find_arg(argname, args, rec=False): |
| 899 | +def _find_arg(argname, args): |
894 | 900 | 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: |
901 | 902 | return i, arg
|
902 | 903 | return None, None
|
903 | 904 |
|
|
0 commit comments