mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:48:22 +00:00

## Summary Given a docstring like: ```python def func(x: int, args: tuple[int]): """Toggle the gizmo. Args: x: Some argument. args: Some other arguments. """ ``` We were considering the `args:` descriptor to be an indented docstring section header (since `Args:`) is a valid header name. This led to very confusing diagnostics. This PR makes the parsing a bit more lax in this case, such that if we see a nested header that's more deeply indented than the preceding header, and the preceding section allows sub-items (like `Args:`), we avoid treating the nested item as a section header. Closes https://github.com/astral-sh/ruff/issues/9426.
170 lines
2.4 KiB
Python
170 lines
2.4 KiB
Python
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
with a hanging indent
|
|
|
|
Returns:
|
|
the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x:
|
|
The whole thing has a hanging indent.
|
|
|
|
Returns:
|
|
the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x:
|
|
The whole thing has a hanging indent.
|
|
|
|
Returns: the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value def
|
|
ghi
|
|
|
|
Returns:
|
|
the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
z: A final argument
|
|
|
|
Returns:
|
|
the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
z: A final argument
|
|
|
|
Returns: the value
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
z: A final argument
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, *args, **kwargs):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
*args: variable arguments
|
|
**kwargs: keyword arguments
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, *args, **kwargs):
|
|
"""Do something.
|
|
|
|
Args:
|
|
*args: variable arguments
|
|
**kwargs: keyword arguments
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, *args, **kwargs):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: the value
|
|
**kwargs: keyword arguments
|
|
"""
|
|
return x
|
|
|
|
|
|
def f(x, *, y, z):
|
|
"""Do something.
|
|
|
|
Args:
|
|
x: some first value
|
|
|
|
Keyword Args:
|
|
y (int): the other value
|
|
z (int): the last value
|
|
|
|
"""
|
|
return x, y, z
|
|
|
|
def f(x):
|
|
"""Do something with valid description.
|
|
|
|
Args:
|
|
----
|
|
x: the value
|
|
|
|
Returns:
|
|
-------
|
|
the value
|
|
"""
|
|
return x
|
|
|
|
|
|
class Test:
|
|
def f(self, /, arg1: int) -> None:
|
|
"""
|
|
Some beauty description.
|
|
|
|
Args:
|
|
arg1: some description of arg
|
|
"""
|
|
|
|
|
|
def select_data(
|
|
query: str,
|
|
args: tuple,
|
|
database: str,
|
|
auto_save: bool,
|
|
) -> None:
|
|
"""This function has an argument `args`, which shouldn't be mistaken for a section.
|
|
|
|
Args:
|
|
query:
|
|
Query template.
|
|
args:
|
|
A list of arguments.
|
|
database:
|
|
Which database to connect to ("origin" or "destination").
|
|
"""
|