diff --git a/src/griffe/dataclasses.py b/src/griffe/dataclasses.py index 88c3da22..f85d3c5a 100644 --- a/src/griffe/dataclasses.py +++ b/src/griffe/dataclasses.py @@ -131,14 +131,14 @@ def as_dict(self, full: bool = False, docstring_parser: Parser = Parser.google, return base -class Argument: - """This class represent a function argument. +class Parameter: + """This class represent a function parameter. Attributes: - name: The argument name. - annotation: The argument annotation, if any. - kind: The argument kind (see [`inspect.Parameter.kind`][]). - default: The argument default, if any. + name: The parameter name. + annotation: The parameter annotation, if any. + kind: The parameter kind (see [`inspect.Parameter.kind`][]). + default: The parameter default, if any. """ def __init__( @@ -149,17 +149,20 @@ def __init__( kind: ParameterKind | None = None, default: str | None = None, ) -> None: - """Initialize the argument. + """Initialize the parameter. Parameters: + name: The parameter name. + annotation: The parameter annotation, if any. + kind: The parameter kind (see [`inspect.Parameter.kind`][]). + default: The parameter default, if any. """ self.name: str = name self.annotation: str | None = annotation self.kind: ParameterKind | None = kind self.default: str | None = default - def as_dict(self, **kwargs) -> dict[str, Any]: - """Return this argument's data as a dictionary. + """Return this parameter's data as a dictionary. Parameters: **kwargs: Additional serialization options. @@ -175,46 +178,48 @@ def as_dict(self, **kwargs) -> dict[str, Any]: } -class Arguments: - """This class is a container for arguments. +class Parameters: + """This class is a container for parameters. - It allows to get arguments using their position (index) or their name. + It allows to get parameters using their position (index) or their name. """ - def __init__(self, *arguments: Argument) -> None: - """Initialize the arguments container. + def __init__(self, *parameters: Parameter) -> None: + """Initialize the parameters container. Parameters: + *parameters: The initial parameters to add to the container. """ - self._arguments_list: list[Argument] = [] - self._arguments_dict: dict[str, Argument] = {} - for argument in arguments: - self.add(argument) + self._parameters_list: list[Parameter] = [] + self._parameters_dict: dict[str, Parameter] = {} + for parameter in parameters: + self.add(parameter) - def __getitem__(self, name_or_index: int | str) -> Argument: + def __getitem__(self, name_or_index: int | str) -> Parameter: if isinstance(name_or_index, int): - return self._arguments_list[name_or_index] - return self._arguments_dict[name_or_index] + return self._parameters_list[name_or_index] + return self._parameters_dict[name_or_index] def __len__(self): - return len(self._arguments_list) + return len(self._parameters_list) def __iter__(self): - return iter(self._arguments_list) + return iter(self._parameters_list) - def add(self, argument: Argument) -> None: - """Add an argument to the container. + def add(self, parameter: Parameter) -> None: + """Add a parameter to the container. Parameters: + parameter: The function parameter to add. Raises: - ValueError: When an argument with the same name is already present. + ValueError: When a parameter with the same name is already present. """ - if argument.name not in self._arguments_dict: - self._arguments_dict[argument.name] = argument - self._arguments_list.append(argument) + if parameter.name not in self._parameters_dict: + self._parameters_dict[parameter.name] = parameter + self._parameters_list.append(parameter) else: - raise ValueError(f"argument {argument.name} already present") + raise ValueError(f"parameter {parameter.name} already present") class Kind(enum.Enum): @@ -545,8 +550,7 @@ class Function(Object): def __init__( self, - *args, - arguments: Arguments | None = None, + parameters: Parameters | None = None, returns: str | None = None, decorators: list[Decorator] | None = None, **kwargs, @@ -555,13 +559,13 @@ def __init__( Parameters: *args: See [`griffe.dataclasses.Object`][]. - arguments: The function arguments. + parameters: The function parameters. returns: The function return annotation. decorators: The function decorators, if any. **kwargs: See [`griffe.dataclasses.Object`][]. """ super().__init__(*args, **kwargs) - self.arguments = arguments or Arguments() + self.parameters = parameters or Parameters() self.returns = returns self.decorators = decorators or [] @@ -576,7 +580,7 @@ def as_dict(self, **kwargs) -> dict[str, Any]: # type: ignore """ base = super().as_dict(**kwargs) base["decorators"] = [dec.as_dict(**kwargs) for dec in self.decorators] - base["arguments"] = [arg.as_dict(**kwargs) for arg in self.arguments] + base["parameters"] = [param.as_dict(**kwargs) for param in self.parameters] base["returns"] = self.returns return base diff --git a/src/griffe/docstrings/dataclasses.py b/src/griffe/docstrings/dataclasses.py index a7e95d66..7e2946c4 100644 --- a/src/griffe/docstrings/dataclasses.py +++ b/src/griffe/docstrings/dataclasses.py @@ -10,8 +10,8 @@ class DocstringSectionKind(enum.Enum): """The possible section kinds.""" text = "text" - arguments = "arguments" - keyword_arguments = "keyword arguments" + parameters = "parameters" + other_parameters = "other parameters" raises = "raises" warns = "warns" returns = "returns" @@ -183,8 +183,8 @@ def as_dict(self, **kwargs) -> dict[str, Any]: return base -class DocstringArgument(DocstringNamedElement): - """This class represent a documented function argument.""" +class DocstringParameter(DocstringNamedElement): + """This class represent a documented function parameter.""" class DocstringAttribute(DocstringNamedElement): diff --git a/src/griffe/docstrings/google.py b/src/griffe/docstrings/google.py index e978ba8d..1ad27760 100644 --- a/src/griffe/docstrings/google.py +++ b/src/griffe/docstrings/google.py @@ -7,9 +7,9 @@ from griffe.docstrings.dataclasses import ( DocstringAdmonition, - DocstringArgument, DocstringAttribute, DocstringException, + DocstringParameter, DocstringReceive, DocstringReturn, DocstringSection, @@ -25,12 +25,14 @@ _warn = warning(__name__) _section_kind = { - "args": DocstringSectionKind.arguments, - "arguments": DocstringSectionKind.arguments, - "params": DocstringSectionKind.arguments, - "parameters": DocstringSectionKind.arguments, - "keyword args": DocstringSectionKind.keyword_arguments, - "keyword arguments": DocstringSectionKind.keyword_arguments, + "args": DocstringSectionKind.parameters, + "arguments": DocstringSectionKind.parameters, + "params": DocstringSectionKind.parameters, + "parameters": DocstringSectionKind.parameters, + "keyword args": DocstringSectionKind.other_parameters, + "keyword parameters": DocstringSectionKind.other_parameters, + "other args": DocstringSectionKind.other_parameters, + "other parameters": DocstringSectionKind.other_parameters, "raises": DocstringSectionKind.raises, "exceptions": DocstringSectionKind.raises, "returns": DocstringSectionKind.returns, @@ -137,8 +139,8 @@ def _read_block(docstring: Docstring, offset: int) -> tuple[str, int]: return "\n".join(block).rstrip("\n"), index - 1 -def _read_arguments(docstring: Docstring, offset: int) -> tuple[list[DocstringArgument], int]: # noqa: WPS231 - arguments = [] +def _read_parameters(docstring: Docstring, offset: int) -> tuple[list[DocstringParameter], int]: # noqa: WPS231 + parameters = [] type_: str annotation: str | None @@ -155,7 +157,7 @@ def _read_arguments(docstring: Docstring, offset: int) -> tuple[list[DocstringAr description = description.lstrip() - # use the type given after the argument name, if any + # use the type given after the parameter name, if any if " " in name_with_type: name, type_ = name_with_type.split(" ", 1) annotation = type_.strip("()") @@ -165,40 +167,40 @@ def _read_arguments(docstring: Docstring, offset: int) -> tuple[list[DocstringAr name = name_with_type # try to use the annotation from the signature try: - annotation = docstring.parent.arguments[name].annotation # type: ignore + annotation = docstring.parent.parameters[name].annotation # type: ignore except (AttributeError, KeyError): annotation = None try: - default = docstring.parent.arguments[name].default # type: ignore + default = docstring.parent.parameters[name].default # type: ignore except (AttributeError, KeyError): default = None if annotation is None: - _warn(docstring, index, f"No type or annotation for argument '{name}'") + _warn(docstring, index, f"No type or annotation for parameter '{name}'") - arguments.append(DocstringArgument(name=name, value=default, annotation=annotation, description=description)) + parameters.append(DocstringParameter(name=name, value=default, annotation=annotation, description=description)) - return arguments, index + return parameters, index -def _read_arguments_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: - arguments, index = _read_arguments(docstring, offset) +def _read_parameters_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: + parameters, index = _read_parameters(docstring, offset) - if arguments: - return DocstringSection(DocstringSectionKind.arguments, arguments), index + if parameters: + return DocstringSection(DocstringSectionKind.parameters, parameters), index - _warn(docstring, index, f"Empty arguments section at line {offset}") + _warn(docstring, index, f"Empty parameters section at line {offset}") return None, index -def _read_keyword_arguments_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: - arguments, index = _read_arguments(docstring, offset) +def _read_other_parameters_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: + parameters, index = _read_parameters(docstring, offset) - if arguments: - return DocstringSection(DocstringSectionKind.keyword_arguments, arguments), index + if parameters: + return DocstringSection(DocstringSectionKind.other_parameters, parameters), index - _warn(docstring, index, f"Empty keyword arguments section at line {offset}") + _warn(docstring, index, f"Empty keyword parameters section at line {offset}") return None, index @@ -453,8 +455,8 @@ def _is_empty_line(line) -> bool: _section_reader = { - DocstringSectionKind.arguments: _read_arguments_section, - DocstringSectionKind.keyword_arguments: _read_keyword_arguments_section, + DocstringSectionKind.parameters: _read_parameters_section, + DocstringSectionKind.other_parameters: _read_other_parameters_section, DocstringSectionKind.raises: _read_raises_section, DocstringSectionKind.warns: _read_warns_section, DocstringSectionKind.examples: _read_examples_section, diff --git a/src/griffe/docstrings/numpy.py b/src/griffe/docstrings/numpy.py index 9a2f6fe9..78152d8c 100644 --- a/src/griffe/docstrings/numpy.py +++ b/src/griffe/docstrings/numpy.py @@ -29,7 +29,7 @@ - Returns: obviously. - Yields: obviously. - Receives: less used than Yields, but very natural/Pythonic as well. -- Other parameters: used here as documentation for keyword arguments. +- Other parameters: used here as documentation for keyword parameters. - Raises: obviously. - Warns: less used than Raises, but very natural/Pythonic as well. - Examples: obviously. Special handling for non-code-blocks `>>>`. @@ -43,8 +43,8 @@ from typing import TYPE_CHECKING, Pattern from griffe.docstrings.dataclasses import ( - DocstringArgument, DocstringAttribute, + DocstringParameter, DocstringRaise, DocstringReceive, DocstringReturn, @@ -62,8 +62,8 @@ _section_kind = { "deprecated": DocstringSectionKind.deprecated, - "parameters": DocstringSectionKind.arguments, - "other parameters": DocstringSectionKind.keyword_arguments, + "parameters": DocstringSectionKind.parameters, + "other parameters": DocstringSectionKind.other_parameters, "returns": DocstringSectionKind.returns, "yields": DocstringSectionKind.yields, "receives": DocstringSectionKind.receives, @@ -190,8 +190,8 @@ def _read_block(docstring: Docstring, offset: int) -> tuple[str, int]: ) -def _read_parameters(docstring: Docstring, offset: int) -> tuple[list[DocstringArgument], int]: # noqa: WPS231 - arguments = [] +def _read_parameters(docstring: Docstring, offset: int) -> tuple[list[DocstringParameter], int]: # noqa: WPS231 + parameters = [] annotation: str | None items, index = _read_block_items(docstring, offset) @@ -220,7 +220,7 @@ def _read_parameters(docstring: Docstring, offset: int) -> tuple[list[DocstringA # try to use the annotation from the signature for name in names: try: - annotation = docstring.parent.arguments[name].annotation # type: ignore + annotation = docstring.parent.parameters[name].annotation # type: ignore break except (AttributeError, KeyError): pass @@ -230,32 +230,32 @@ def _read_parameters(docstring: Docstring, offset: int) -> tuple[list[DocstringA if default is None: for name in names: try: - default = docstring.parent.arguments[name].default # type: ignore + default = docstring.parent.parameters[name].default # type: ignore break except (AttributeError, KeyError): pass for name in names: - arguments.append(DocstringArgument(name, value=default, annotation=annotation, description=description)) + parameters.append(DocstringParameter(name, value=default, annotation=annotation, description=description)) - return arguments, index + return parameters, index def _read_parameters_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: - arguments, index = _read_parameters(docstring, offset) + parameters, index = _read_parameters(docstring, offset) - if arguments: - return DocstringSection(DocstringSectionKind.arguments, arguments), index + if parameters: + return DocstringSection(DocstringSectionKind.parameters, parameters), index _warn(docstring, index, f"Empty parameters section at line {offset}") return None, index def _read_other_parameters_section(docstring: Docstring, offset: int) -> tuple[DocstringSection | None, int]: - arguments, index = _read_parameters(docstring, offset) + parameters, index = _read_parameters(docstring, offset) - if arguments: - return DocstringSection(DocstringSectionKind.keyword_arguments, arguments), index + if parameters: + return DocstringSection(DocstringSectionKind.other_parameters, parameters), index _warn(docstring, index, f"Empty other parameters section at line {offset}") return None, index @@ -464,8 +464,8 @@ def _read_examples_section(docstring: Docstring, offset: int) -> tuple[Docstring _section_reader = { - DocstringSectionKind.arguments: _read_parameters_section, - DocstringSectionKind.keyword_arguments: _read_other_parameters_section, + DocstringSectionKind.parameters: _read_parameters_section, + DocstringSectionKind.other_parameters: _read_other_parameters_section, DocstringSectionKind.deprecated: _read_deprecated_section, DocstringSectionKind.raises: _read_raises_section, DocstringSectionKind.warns: _read_warns_section, diff --git a/src/griffe/docstrings/rst.py b/src/griffe/docstrings/rst.py index fa207549..ed0287a8 100644 --- a/src/griffe/docstrings/rst.py +++ b/src/griffe/docstrings/rst.py @@ -11,9 +11,9 @@ from typing import TYPE_CHECKING, Any, Callable, FrozenSet, TypedDict from griffe.docstrings.dataclasses import ( - DocstringArgument, DocstringAttribute, DocstringException, + DocstringParameter, DocstringReturn, DocstringSection, DocstringSectionKind, @@ -77,7 +77,7 @@ class ParsedValues: """Values parsed from the docstring to be used to produce sections.""" description: list[str] = field(default_factory=list) - parameters: dict[str, DocstringArgument] = field(default_factory=dict) + parameters: dict[str, DocstringParameter] = field(default_factory=dict) param_types: dict[str, str] = field(default_factory=dict) attributes: dict[str, DocstringAttribute] = field(default_factory=dict) attribute_types: dict[str, str] = field(default_factory=dict) @@ -149,7 +149,7 @@ def _read_parameter(docstring: Docstring, offset: int, parsed_values: ParsedValu annotation = _determine_param_annotation(docstring, name, directive_type, parsed_values) default = _determine_param_default(docstring, name) - parsed_values.parameters[name] = DocstringArgument( + parsed_values.parameters[name] = DocstringParameter( name=name, annotation=annotation, description=parsed_directive.value, @@ -161,7 +161,7 @@ def _read_parameter(docstring: Docstring, offset: int, parsed_values: ParsedValu def _determine_param_default(docstring: Docstring, name: str) -> str | None: try: - return docstring.parent.arguments[name.lstrip()].default # type: ignore + return docstring.parent.parameters[name.lstrip()].default # type: ignore except (AttributeError, KeyError): return None @@ -188,7 +188,7 @@ def _determine_param_annotation( if annotation is None: try: - annotation = docstring.parent.arguments[name.lstrip()].annotation # type: ignore + annotation = docstring.parent.parameters[name.lstrip()].annotation # type: ignore except (AttributeError, KeyError): _warn(docstring, 0, f"No matching parameter for '{name}'") @@ -389,7 +389,7 @@ def _parsed_values_to_sections(parsed_values: ParsedValues) -> list[DocstringSec result = [DocstringSection(DocstringSectionKind.text, text)] if parsed_values.parameters: param_values = list(parsed_values.parameters.values()) - result.append(DocstringSection(DocstringSectionKind.arguments, param_values)) + result.append(DocstringSection(DocstringSectionKind.parameters, param_values)) if parsed_values.attributes: attribute_values = list(parsed_values.attributes.values()) result.append(DocstringSection(DocstringSectionKind.attributes, attribute_values)) diff --git a/src/griffe/visitor.py b/src/griffe/visitor.py index 3b6a740e..d4348661 100644 --- a/src/griffe/visitor.py +++ b/src/griffe/visitor.py @@ -35,7 +35,7 @@ from pathlib import Path from griffe.collections import lines_collection -from griffe.dataclasses import Argument, Arguments, Class, Data, Decorator, Docstring, Function, Kind, Module +from griffe.dataclasses import Class, Data, Decorator, Docstring, Function, Kind, Module, Parameter, Parameters from griffe.extended_ast import LastNodeError from griffe.extensions import Extensions from griffe.extensions.base import _BaseVisitor # noqa: WPS450 @@ -264,8 +264,8 @@ def _get_instance_names(node): # ========================================================== -# arguments -def _get_argument_default(node, filepath): +# parameters +def _get_parameter_default(node, filepath): if node is None: return None if isinstance(node, Constant): @@ -374,8 +374,8 @@ def handle_function(self, node, labels: set | None = None): # noqa: WPS231 else: lineno = node.lineno - # handle arguments - arguments = Arguments() + # handle parameters + parameters = Parameters() annotation: str | None # TODO: probably some optimisations to do here @@ -395,17 +395,17 @@ def handle_function(self, node, labels: set | None = None): # noqa: WPS231 ) for (arg, kind), default in args_kinds_defaults: annotation = _get_annotation(arg.annotation) - default = _get_argument_default(default, self.filepath) - arguments.add(Argument(arg.arg, annotation=annotation, kind=kind, default=default)) + default = _get_parameter_default(default, self.filepath) + parameters.add(Parameter(arg.arg, annotation=annotation, kind=kind, default=default)) if node.args.vararg: annotation = _get_annotation(node.args.vararg.annotation) - arguments.add( - Argument( + parameters.add( + Parameter( f"*{node.args.vararg.arg}", annotation=annotation, kind=inspect.Parameter.VAR_POSITIONAL, - default=None, + default="()", ) ) @@ -421,16 +421,19 @@ def handle_function(self, node, labels: set | None = None): # noqa: WPS231 ) for kwarg, default in kwargs_defaults: # noqa: WPS440 annotation = _get_annotation(kwarg.annotation) - default = _get_argument_default(default, self.filepath) - arguments.add( - Argument(kwarg.arg, annotation=annotation, kind=inspect.Parameter.KEYWORD_ONLY, default=default) + default = _get_parameter_default(default, self.filepath) + parameters.add( + Parameter(kwarg.arg, annotation=annotation, kind=inspect.Parameter.KEYWORD_ONLY, default=default) ) if node.args.kwarg: annotation = _get_annotation(node.args.kwarg.annotation) - arguments.add( - Argument( - f"**{node.args.kwarg.arg}", annotation=annotation, kind=inspect.Parameter.VAR_KEYWORD, default=None + parameters.add( + Parameter( + f"**{node.args.kwarg.arg}", + annotation=annotation, + kind=inspect.Parameter.VAR_KEYWORD, + default="{}", ) ) @@ -438,7 +441,7 @@ def handle_function(self, node, labels: set | None = None): # noqa: WPS231 name=node.name, lineno=lineno, endlineno=node.end_lineno, - arguments=arguments, + parameters=parameters, returns=_get_annotation(node.returns), decorators=decorators, docstring=_get_docstring(node), diff --git a/tests/fixtures/functions/arguments.py b/tests/fixtures/functions/parameters.py similarity index 100% rename from tests/fixtures/functions/arguments.py rename to tests/fixtures/functions/parameters.py diff --git a/tests/test_cli.py b/tests/test_cli.py index 3c4925ef..a83146df 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -14,7 +14,7 @@ def test_show_help(capsys): """ Show help. - Arguments: + Parameters: capsys: Pytest fixture to capture output. """ with pytest.raises(SystemExit): diff --git a/tests/test_docstrings/helpers.py b/tests/test_docstrings/helpers.py index ffe0d988..0dcf4477 100644 --- a/tests/test_docstrings/helpers.py +++ b/tests/test_docstrings/helpers.py @@ -4,8 +4,7 @@ from typing import Any, Callable, List, Tuple, Union -from griffe.dataclasses import Class, Data, Docstring, Function, Module -from griffe.docstrings.dataclasses import DocstringArgument, DocstringAttribute, DocstringElement, DocstringSection +from griffe.docstrings.dataclasses import DocstringAttribute, DocstringElement, DocstringParameter, DocstringSection ParentType = Union[Module, Class, Function, Data, None] ParseResultType = Tuple[List[DocstringSection], List[str]] @@ -45,10 +44,12 @@ def parse(docstring: str, parent: ParentType = None, **parser_opts: Any) -> Pars return parse # type: ignore -def assert_argument_equal(actual: DocstringArgument, expected: DocstringArgument) -> None: - """Help assert docstring arguments are equal. +def assert_parameter_equal(actual: DocstringParameter, expected: DocstringParameter) -> None: + """Help assert docstring parameters are equal. Parameters: + actual: The actual parameter. + expected: The expected parameter. """ assert actual.name == expected.name assert_element_equal(actual, expected) diff --git a/tests/test_docstrings/test_google.py b/tests/test_docstrings/test_google.py index 342b2f3a..24024682 100644 --- a/tests/test_docstrings/test_google.py +++ b/tests/test_docstrings/test_google.py @@ -2,7 +2,7 @@ from __future__ import annotations -from griffe.dataclasses import Argument, Arguments, Function +from griffe.dataclasses import Function, Parameter, Parameters from griffe.docstrings import google from griffe.docstrings.dataclasses import DocstringSectionKind from tests.test_docstrings.helpers import parser @@ -35,8 +35,8 @@ def test_multiline_docstring(): def test_multiple_lines_in_sections_items(): """Parse multi-line item description.""" docstring = """ - Arguments: - p (int): This argument + Parameters: + p (int): This parameter has a description spawning on multiple lines. @@ -145,9 +145,9 @@ def test_parse_without_parent(): ) assert len(sections) == 4 - assert len(warnings) == 6 # missing annotations for arguments and return + assert len(warnings) == 6 # missing annotations for parameters and return for warning in warnings[:-1]: - assert "argument" in warning + assert "parameter" in warning assert "return" in warnings[-1] @@ -168,16 +168,16 @@ def test_parse_without_annotations(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x"), - Argument("y"), + parameters=Parameters( + Parameter("x"), + Parameter("y"), ), ), ) assert len(sections) == 3 assert len(warnings) == 3 for warning in warnings[:-1]: - assert "argument" in warning + assert "parameter" in warning assert "return" in warnings[-1] @@ -187,7 +187,7 @@ def test_parse_with_annotations(): Parameters: x: X value. - Keyword Arguments: + Keyword Parameters: y: Y value. Returns: @@ -198,9 +198,9 @@ def test_parse_with_annotations(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x", annotation="int"), - Argument("y", annotation="int"), + parameters=Parameters( + Parameter("x", annotation="int"), + Parameter("y", annotation="int"), ), returns="int", ), @@ -283,9 +283,9 @@ def test_parse_examples_sections(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x", annotation="int"), - Argument("y", annotation="int"), + parameters=Parameters( + Parameter("x", annotation="int"), + Parameter("y", annotation="int"), ), returns="int", ), @@ -357,47 +357,47 @@ def test_close_sections(): # ============================================================================================= -# Arguments sections +# Parameters sections def test_parse_args_and_kwargs(): """Parse args and kwargs.""" docstring = """ - Arguments: - a (str): an argument. - *args (str): args arguments. - **kwargs (str): kwargs arguments. + Parameters: + a (str): a parameter. + *args (str): args parameters. + **kwargs (str): kwargs parameters. """ sections, warnings = parse(docstring) assert len(sections) == 1 - expected_arguments = {"a": "an argument.", "*args": "args arguments.", "**kwargs": "kwargs arguments."} - for argument in sections[0].value: - assert argument.name in expected_arguments - assert expected_arguments[argument.name] == argument.description + expected_parameters = {"a": "a parameter.", "*args": "args parameters.", "**kwargs": "kwargs parameters."} + for parameter in sections[0].value: + assert parameter.name in expected_parameters + assert expected_parameters[parameter.name] == parameter.description assert not warnings def test_parse_args_kwargs_keyword_only(): """Parse args and kwargs.""" docstring = """ - Arguments: - a (str): an argument. - *args (str): args arguments. + Parameters: + a (str): a parameter. + *args (str): args parameters. Keyword Args: - **kwargs (str): kwargs arguments. + **kwargs (str): kwargs parameters. """ sections, warnings = parse(docstring) assert len(sections) == 2 - expected_arguments = {"a": "an argument.", "*args": "args arguments."} - for argument in sections[0].value: - assert argument.name in expected_arguments - assert expected_arguments[argument.name] == argument.description + expected_parameters = {"a": "a parameter.", "*args": "args parameters."} + for parameter in sections[0].value: + assert parameter.name in expected_parameters + assert expected_parameters[parameter.name] == parameter.description - expected_arguments = {"**kwargs": "kwargs arguments."} - for kwargument in sections[1].value: - assert kwargument.name in expected_arguments - assert expected_arguments[kwargument.name] == kwargument.description + expected_parameters = {"**kwargs": "kwargs parameters."} + for kwarg in sections[1].value: + assert kwarg.name in expected_parameters + assert expected_parameters[kwarg.name] == kwarg.description assert not warnings @@ -419,17 +419,17 @@ def test_parse_types_in_docstring(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x"), - Argument("y"), + parameters=Parameters( + Parameter("x"), + Parameter("y"), ), ), ) assert len(sections) == 3 assert not warnings - assert sections[0].kind is DocstringSectionKind.arguments - assert sections[1].kind is DocstringSectionKind.keyword_arguments + assert sections[0].kind is DocstringSectionKind.parameters + assert sections[1].kind is DocstringSectionKind.other_parameters assert sections[2].kind is DocstringSectionKind.returns (argx,) = sections[0].value # noqa: WPS460 @@ -465,18 +465,18 @@ def test_parse_optional_type_in_docstring(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x", default="1"), - Argument("y", default="None"), - Argument("z", default="None"), + parameters=Parameters( + Parameter("x", default="1"), + Parameter("y", default="None"), + Parameter("z", default="None"), ), ), ) assert len(sections) == 2 assert not warnings - assert sections[0].kind is DocstringSectionKind.arguments - assert sections[1].kind is DocstringSectionKind.keyword_arguments + assert sections[0].kind is DocstringSectionKind.parameters + assert sections[1].kind is DocstringSectionKind.other_parameters argx, argy = sections[0].value (argz,) = sections[1].value # noqa: WPS460 @@ -514,9 +514,9 @@ def test_prefer_docstring_types_over_annotations(): docstring, parent=Function( "func", - arguments=Arguments( - Argument("x", annotation="int"), - Argument("y", annotation="int"), + parameters=Parameters( + Parameter("x", annotation="int"), + Parameter("y", annotation="int"), ), returns="int", ), @@ -524,8 +524,8 @@ def test_prefer_docstring_types_over_annotations(): assert len(sections) == 3 assert not warnings - assert sections[0].kind is DocstringSectionKind.arguments - assert sections[1].kind is DocstringSectionKind.keyword_arguments + assert sections[0].kind is DocstringSectionKind.parameters + assert sections[1].kind is DocstringSectionKind.other_parameters assert sections[2].kind is DocstringSectionKind.returns (argx,) = sections[0].value # noqa: WPS460 @@ -544,7 +544,7 @@ def test_prefer_docstring_types_over_annotations(): assert returns.description == "Sum X + Y + Z." -def test_argument_line_without_colon(): +def test_parameter_line_without_colon(): """Warn when missing colon.""" docstring = """ Parameters: @@ -558,7 +558,7 @@ def test_argument_line_without_colon(): assert "Empty" in warnings[1] -def test_argument_line_without_colon_keyword_only(): +def test_parameter_line_without_colon_keyword_only(): """Warn when missing colon.""" docstring = """ Keyword Args: @@ -573,8 +573,8 @@ def test_argument_line_without_colon_keyword_only(): # TODO: possible feature -# def test_extra_argument(): -# """Warn on extra argument in docstring.""" +# def test_extra_parameter(): +# """Warn on extra parameter in docstring.""" # docstring = """ # Parameters: # x: Integer. @@ -587,8 +587,8 @@ def test_argument_line_without_colon_keyword_only(): # TODO: possible feature -# def test_missing_argument(): -# """Warn on missing argument in docstring.""" +# def test_missing_parameter(): +# """Warn on missing parameter in docstring.""" # docstring = """ # Parameters: # x: Integer. diff --git a/tests/test_docstrings/test_numpy.py b/tests/test_docstrings/test_numpy.py index 2f3f8e43..d8dda7cf 100644 --- a/tests/test_docstrings/test_numpy.py +++ b/tests/test_docstrings/test_numpy.py @@ -2,11 +2,11 @@ from __future__ import annotations -from griffe.dataclasses import Argument, Arguments, Function +from griffe.dataclasses import Function, Parameter, Parameters from griffe.docstrings import numpy from griffe.docstrings.dataclasses import ( - DocstringArgument, DocstringAttribute, + DocstringParameter, DocstringRaise, DocstringReceive, DocstringReturn, @@ -14,7 +14,7 @@ DocstringWarn, DocstringYield, ) -from tests.test_docstrings.helpers import assert_argument_equal, assert_attribute_equal, assert_element_equal, parser +from tests.test_docstrings.helpers import assert_attribute_equal, assert_element_equal, assert_parameter_equal, parser parse = parser(numpy) @@ -129,9 +129,9 @@ def test_retrieve_annotation_from_parent(): a """ - sections, _ = parse(docstring, parent=Function("func", arguments=Arguments(Argument("a", annotation="str")))) + sections, _ = parse(docstring, parent=Function("func", parameters=Parameters(Parameter("a", annotation="str")))) assert len(sections) == 1 - assert_argument_equal(sections[0].value[0], DocstringArgument("a", description="", annotation="str")) + assert_parameter_equal(sections[0].value[0], DocstringParameter("a", description="", annotation="str")) def test_prefer_docstring_type_over_annotation(): @@ -142,9 +142,9 @@ def test_prefer_docstring_type_over_annotation(): a : int """ - sections, _ = parse(docstring, parent=Function("func", arguments=Arguments(Argument("a", annotation="str")))) + sections, _ = parse(docstring, parent=Function("func", parameters=Parameters(Parameter("a", annotation="str")))) assert len(sections) == 1 - assert_argument_equal(sections[0].value[0], DocstringArgument("a", description="", annotation="int")) + assert_parameter_equal(sections[0].value[0], DocstringParameter("a", description="", annotation="int")) def test_deprecated_section(): diff --git a/tests/test_docstrings/test_rst.py b/tests/test_docstrings/test_rst.py index c1b4d749..8f1e4591 100644 --- a/tests/test_docstrings/test_rst.py +++ b/tests/test_docstrings/test_rst.py @@ -6,16 +6,16 @@ import pytest -from griffe.dataclasses import Argument, Arguments, Class, Function +from griffe.dataclasses import Class, Function, Parameter, Parameters from griffe.docstrings import rst from griffe.docstrings.dataclasses import ( - DocstringArgument, DocstringAttribute, DocstringException, + DocstringParameter, DocstringReturn, DocstringSectionKind, ) -from tests.test_docstrings.helpers import assert_argument_equal, assert_attribute_equal, assert_element_equal, parser +from tests.test_docstrings.helpers import assert_attribute_equal, assert_element_equal, assert_parameter_equal, parser SOME_NAME = "foo" SOME_TEXT = "descriptive test text" @@ -40,7 +40,7 @@ def test_parse__description_only_docstring__single_markdown_section(docstring): """Parse a single or multiline docstring. - Arguments: + Parameters: docstring: A parametrized docstring. """ sections, warnings = parse(docstring) @@ -86,8 +86,8 @@ def test_parse__param_field__param_section(): """ ) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal(sections[1].value[0], DocstringArgument(SOME_NAME, description=SOME_TEXT)) + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal(sections[1].value[0], DocstringParameter(SOME_NAME, description=SOME_TEXT)) def test_parse__only_param_field__empty_markdown(): @@ -104,7 +104,7 @@ def test_parse__only_param_field__empty_markdown(): "param", "parameter", "arg", - "argument", + "parameter", "key", "keyword", ], @@ -112,7 +112,7 @@ def test_parse__only_param_field__empty_markdown(): def test_parse__all_param_names__param_section(param_directive_name): """Parse all parameters directives. - Arguments: + Parameters: param_directive_name: A parametrized directive name. """ sections, _ = parse( @@ -123,8 +123,8 @@ def test_parse__all_param_names__param_section(param_directive_name): """ ) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal(sections[1].value[0], DocstringArgument(SOME_NAME, description=SOME_TEXT)) + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal(sections[1].value[0], DocstringParameter(SOME_NAME, description=SOME_TEXT)) @pytest.mark.parametrize( @@ -147,15 +147,15 @@ def test_parse__all_param_names__param_section(param_directive_name): def test_parse__param_field_multi_line__param_section(docstring): """Parse multiline directives. - Arguments: + Parameters: docstring: A parametrized docstring. """ sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, description=f"{SOME_TEXT} {SOME_EXTRA_TEXT}"), + DocstringParameter(SOME_NAME, description=f"{SOME_TEXT} {SOME_EXTRA_TEXT}"), ) @@ -169,10 +169,10 @@ def test_parse__param_field_for_function__param_section_with_kind(): sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, description=SOME_TEXT), + DocstringParameter(SOME_NAME, description=SOME_TEXT), ) @@ -186,10 +186,10 @@ def test_parse__param_field_docs_type__param_section_with_type(): sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, annotation="str", description=SOME_TEXT), + DocstringParameter(SOME_NAME, annotation="str", description=SOME_TEXT), ) @@ -204,10 +204,10 @@ def test_parse__param_field_type_field__param_section_with_type(): sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, annotation="str", description=SOME_TEXT), + DocstringParameter(SOME_NAME, annotation="str", description=SOME_TEXT), ) @@ -222,10 +222,10 @@ def test_parse__param_field_type_field_first__param_section_with_type(): sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, annotation="str", description=SOME_TEXT), + DocstringParameter(SOME_NAME, annotation="str", description=SOME_TEXT), ) @@ -233,7 +233,7 @@ def test_parse__param_field_type_field_first__param_section_with_type(): def test_parse__param_field_type_field_or_none__param_section_with_optional(union): """Parse parameters with separated union types. - Arguments: + Parameters: union: A parametrized union type. """ docstring = f""" @@ -245,10 +245,10 @@ def test_parse__param_field_type_field_or_none__param_section_with_optional(unio sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, annotation=union.replace(" or ", " | "), description=SOME_TEXT), + DocstringParameter(SOME_NAME, annotation=union.replace(" or ", " | "), description=SOME_TEXT), ) @@ -262,13 +262,13 @@ def test_parse__param_field_annotate_type__param_section_with_type(): sections, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", annotation="str", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", annotation="str", kind=None))), ) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument(SOME_NAME, annotation="str", description=SOME_TEXT), + DocstringParameter(SOME_NAME, annotation="str", description=SOME_TEXT), ) assert not warnings @@ -283,10 +283,10 @@ def test_parse__param_field_no_matching_param__result_from_docstring(): sections, _ = parse(docstring) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument("other", description=SOME_TEXT), + DocstringParameter("other", description=SOME_TEXT), ) @@ -300,13 +300,13 @@ def test_parse__param_field_with_default__result_from_docstring(): sections, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", kind=None, default=repr("")))), + parent=Function("func", parameters=Parameters(Parameter("foo", kind=None, default=repr("")))), ) assert len(sections) == 2 - assert sections[1].kind is DocstringSectionKind.arguments - assert_argument_equal( + assert sections[1].kind is DocstringSectionKind.parameters + assert_parameter_equal( sections[1].value[0], - DocstringArgument("foo", description=SOME_TEXT, value=repr("")), + DocstringParameter("foo", description=SOME_TEXT, value=repr("")), ) assert not warnings @@ -358,7 +358,7 @@ def test_parse__param_twice__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", kind=None))), ) assert "Duplicate parameter entry for 'foo'" in warnings[0] @@ -374,7 +374,7 @@ def test_parse__param_type_twice_doc__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", kind=None))), ) assert "Duplicate parameter information for 'foo'" in warnings[0] @@ -390,7 +390,7 @@ def test_parse__param_type_twice_type_directive_first__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", kind=None))), ) assert "Duplicate parameter information for 'foo'" in warnings[0] @@ -406,7 +406,7 @@ def test_parse__param_type_twice_annotated__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", annotation="str", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", annotation="str", kind=None))), ) assert "Duplicate parameter information for 'foo'" in warnings[0] @@ -422,7 +422,7 @@ def test_parse__param_type_no_type__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", annotation="str", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", annotation="str", kind=None))), ) assert "Failed to get ':directive: value' pair from" in warnings[0] @@ -438,7 +438,7 @@ def test_parse__param_type_no_name__error_message(): _, warnings = parse( docstring, - parent=Function("func", arguments=Arguments(Argument("foo", annotation="str", kind=None))), + parent=Function("func", parameters=Parameters(Parameter("foo", annotation="str", kind=None))), ) assert "Failed to get parameter name from" in warnings[0] @@ -463,7 +463,7 @@ def test_parse__param_type_no_name__error_message(): def test_parse__attribute_field_multi_line__param_section(docstring): """Parse multiline attributes. - Arguments: + Parameters: docstring: A parametrized docstring. """ sections, warnings = parse(docstring) @@ -487,7 +487,7 @@ def test_parse__attribute_field_multi_line__param_section(docstring): def test_parse__all_attribute_names__param_section(attribute_directive_name): """Parse all attributes directives. - Arguments: + Parameters: attribute_directive_name: A parametrized directive name. """ sections, warnings = parse( @@ -767,7 +767,7 @@ def test_parse__multiple_raises_directive__exception_section_with_two(): def test_parse__all_exception_names__param_section(raise_directive_name): """Parse all raise directives. - Arguments: + Parameters: raise_directive_name: A parametrized directive name. """ sections, _ = parse( diff --git a/tests/test_functions.py b/tests/test_functions.py index fb2900ea..ac70a95d 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -8,156 +8,156 @@ loader = GriffeLoader() -def test_loading_functions_arguments(): # noqa: WPS218 - """Test functions arguments loading.""" - module = loader.load_module(FIXTURES_DIR / "functions" / "arguments.py") +def test_loading_functions_parameters(): # noqa: WPS218 + """Test functions parameters loading.""" + module = loader.load_module(FIXTURES_DIR / "functions" / "parameters.py") assert module.members assert len(module.members) == 11 # noqa: WPS432 function = module["f_posonly"] - assert len(function.arguments) == 1 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None + assert len(function.parameters) == 1 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None function = module["f_posonly_default"] - assert len(function.arguments) == 1 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default == "0" + assert len(function.parameters) == 1 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default == "0" function = module["f_posonly_poskw"] - assert len(function.arguments) == 2 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default is None + assert len(function.parameters) == 2 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default is None function = module["f_posonly_poskw_default"] - assert len(function.arguments) == 2 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default == "0" + assert len(function.parameters) == 2 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default == "0" function = module["f_posonly_default_poskw_default"] - assert len(function.arguments) == 2 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default == "0" - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default == "1" + assert len(function.parameters) == 2 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default == "0" + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default == "1" function = module["f_posonly_poskw_kwonly"] - assert len(function.arguments) == 3 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default is None - arg = function.arguments[2] - assert arg is function.arguments["kwonly"] - assert arg.name == "kwonly" - assert arg.kind is inspect.Parameter.KEYWORD_ONLY - assert arg.default is None + assert len(function.parameters) == 3 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default is None + param = function.parameters[2] + assert param is function.parameters["kwonly"] + assert param.name == "kwonly" + assert param.kind is inspect.Parameter.KEYWORD_ONLY + assert param.default is None function = module["f_posonly_poskw_kwonly_default"] - assert len(function.arguments) == 3 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default is None - arg = function.arguments[2] - assert arg is function.arguments["kwonly"] - assert arg.name == "kwonly" - assert arg.kind is inspect.Parameter.KEYWORD_ONLY - assert arg.default == "0" + assert len(function.parameters) == 3 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default is None + param = function.parameters[2] + assert param is function.parameters["kwonly"] + assert param.name == "kwonly" + assert param.kind is inspect.Parameter.KEYWORD_ONLY + assert param.default == "0" function = module["f_posonly_poskw_default_kwonly_default"] - assert len(function.arguments) == 3 - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default is None - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default == "0" - arg = function.arguments[2] - assert arg is function.arguments["kwonly"] - assert arg.name == "kwonly" - assert arg.kind is inspect.Parameter.KEYWORD_ONLY - assert arg.default == "1" + assert len(function.parameters) == 3 + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default is None + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default == "0" + param = function.parameters[2] + assert param is function.parameters["kwonly"] + assert param.name == "kwonly" + assert param.kind is inspect.Parameter.KEYWORD_ONLY + assert param.default == "1" function = module["f_posonly_default_poskw_default_kwonly_default"] - arg = function.arguments[0] - assert arg is function.arguments["posonly"] - assert arg.name == "posonly" - assert arg.kind is inspect.Parameter.POSITIONAL_ONLY - assert arg.default == "0" - arg = function.arguments[1] - assert arg is function.arguments["poskw"] - assert arg.name == "poskw" - assert arg.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD - assert arg.default == "1" - arg = function.arguments[2] - assert arg is function.arguments["kwonly"] - assert arg.name == "kwonly" - assert arg.kind is inspect.Parameter.KEYWORD_ONLY - assert arg.default == "2" + param = function.parameters[0] + assert param is function.parameters["posonly"] + assert param.name == "posonly" + assert param.kind is inspect.Parameter.POSITIONAL_ONLY + assert param.default == "0" + param = function.parameters[1] + assert param is function.parameters["poskw"] + assert param.name == "poskw" + assert param.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD + assert param.default == "1" + param = function.parameters[2] + assert param is function.parameters["kwonly"] + assert param.name == "kwonly" + assert param.kind is inspect.Parameter.KEYWORD_ONLY + assert param.default == "2" function = module["f_var"] - assert len(function.arguments) == 3 - arg = function.arguments[0] - assert arg.name == "*args" - assert arg.annotation == "str" - arg = function.arguments[1] - assert arg.annotation is None - arg = function.arguments[2] - assert arg.name == "**kwargs" - assert arg.annotation == "int" + assert len(function.parameters) == 3 + param = function.parameters[0] + assert param.name == "*args" + assert param.annotation == "str" + param = function.parameters[1] + assert param.annotation is None + param = function.parameters[2] + assert param.name == "**kwargs" + assert param.annotation == "int" function = module["f_annorations"] - assert len(function.arguments) == 4 - arg = function.arguments[0] - assert arg.annotation == "str" - arg = function.arguments[1] - assert arg.annotation == "Any" - arg = function.arguments[2] - assert arg.annotation == "typing.Optional[typing.List[int]]" - arg = function.arguments[3] - assert arg.annotation == "float | None" + assert len(function.parameters) == 4 + param = function.parameters[0] + assert param.annotation == "str" + param = function.parameters[1] + assert param.annotation == "Any" + param = function.parameters[2] + assert param.annotation == "typing.Optional[typing.List[int]]" + param = function.parameters[3] + assert param.annotation == "float | None"