Arguments#

class astroid.nodes.Arguments(vararg: str | None, kwarg: str | None, parent: NodeNG, vararg_node: AssignName | None = None, kwarg_node: AssignName | None = None)[source]#

Bases: AssignTypeNode

Class representing an ast.arguments node.

An Arguments node represents that arguments in a function definition.

>>> import astroid
>>> node = astroid.extract_node('def foo(bar): pass')
>>> node
<FunctionDef.foo l.1 at 0x7effe1db8198>
>>> node.args
<Arguments l.1 at 0x7effe1db82e8>
annotations: list[NodeNG | None]#

The type annotations of arguments that can be passed positionally.

args: list[AssignName] | None#

The names of the required arguments.

Can be None if the associated function does not have a retrievable signature and the arguments are therefore unknown. This can happen with (builtin) functions implemented in C that have incomplete signature information.

property arguments#

Get all the arguments for this node. This includes: * Positional only arguments * Positional arguments * Keyword arguments * Variable arguments (.e.g *args) * Variable keyword arguments (e.g **kwargs)

assigned_stmts(node: node_classes.AssignedStmtsPossibleNode = None, context: InferenceContext | None = None, assign_path: list[int] | None = None) Any#

Returns the assigned statement (non inferred) according to the assignment type. See astroid/protocols.py for actual implementation.

default_value(argname)[source]#

Get the default value for an argument.

Parameters:

argname (str) – The name of the argument to get the default value for.

Raises:

NoDefault – If there is no default value defined for the given argument.

defaults: list[NodeNG] | None#

The default values for arguments that can be passed positionally.

find_argname(argname, rec='DEPRECATED_ARGUMENT_DEFAULT')[source]#

Get the index and AssignName node for given name.

Parameters:

argname (str) – The name of the argument to search for.

Returns:

The index and node for the argument.

Return type:

tuple(str or None, AssignName or None)

format_args(*, skippable_names: set[str] | None = None) str[source]#

Get the arguments formatted as string.

Returns:

The formatted arguments.

Return type:

str

property fromlineno: int#

The first line that this node appears on in the source code.

Can also return 0 if the line can not be determined.

get_children()[source]#

Get the child nodes below this node.

is_argument(name) bool[source]#

Check if the given name is defined in the arguments.

Parameters:

name (str) – The name to check for.

Returns:

Whether the given name is defined in the arguments,

kw_defaults: list[NodeNG | None] | None#

The default values for keyword arguments that cannot be passed positionally.

kwarg#

The name of the variable length keyword arguments.

kwarg_node: AssignName | None#

The node for variable keyword arguments

kwargannotation: NodeNG | None#

The type annotation for the variable length keyword arguments.

kwonlyargs: list[AssignName]#

The keyword arguments that cannot be passed positionally.

kwonlyargs_annotations: list[NodeNG | None]#

The type annotations of arguments that cannot be passed positionally.

posonlyargs: list[AssignName]#

The arguments that can only be passed positionally.

posonlyargs_annotations: list[NodeNG | None]#

The type annotations of arguments that can only be passed positionally.

postinit(args: list[AssignName] | None, defaults: list[NodeNG] | None, kwonlyargs: list[AssignName], kw_defaults: list[NodeNG | None] | None, annotations: list[NodeNG | None], posonlyargs: list[AssignName], kwonlyargs_annotations: list[NodeNG | None], posonlyargs_annotations: list[NodeNG | None], varargannotation: NodeNG | None = None, kwargannotation: NodeNG | None = None, type_comment_args: list[NodeNG | None] | None = None, type_comment_kwonlyargs: list[NodeNG | None] | None = None, type_comment_posonlyargs: list[NodeNG | None] | None = None) None[source]#
type_comment_args: list[NodeNG | None]#

The type annotation, passed by a type comment, of each argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_kwonlyargs: list[NodeNG | None]#

The type annotation, passed by a type comment, of each keyword only argument.

If an argument does not have a type comment, the value for that argument will be None.

type_comment_posonlyargs: list[NodeNG | None]#

The type annotation, passed by a type comment, of each positional argument.

If an argument does not have a type comment, the value for that argument will be None.

vararg#

The name of the variable length arguments.

vararg_node: AssignName | None#

The node for variable length arguments

varargannotation: NodeNG | None#

The type annotation for the variable length arguments.