mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Disambiguate argument descriptors from section headers (#9427)
## 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.
This commit is contained in:
parent
d5a439cbd3
commit
04afdf177b
8 changed files with 200 additions and 8 deletions
|
@ -27,4 +27,27 @@ sections.py:144:5: D214 [*] Section is over-indented ("Returns")
|
|||
148 148 | A value of some sort.
|
||||
149 149 |
|
||||
|
||||
sections.py:558:5: D214 [*] Section is over-indented ("Returns")
|
||||
|
|
||||
557 | def titlecase_sub_section_header():
|
||||
558 | """Below, `Returns:` should be considered a section header.
|
||||
| _____^
|
||||
559 | |
|
||||
560 | | Args:
|
||||
561 | | Here's a note.
|
||||
562 | |
|
||||
563 | | Returns:
|
||||
564 | | """
|
||||
| |_______^ D214
|
||||
|
|
||||
= help: Remove over-indentation from "Returns"
|
||||
|
||||
ℹ Safe fix
|
||||
560 560 | Args:
|
||||
561 561 | Here's a note.
|
||||
562 562 |
|
||||
563 |- Returns:
|
||||
563 |+ Returns:
|
||||
564 564 | """
|
||||
|
||||
|
||||
|
|
|
@ -498,4 +498,74 @@ sections.py:527:5: D407 [*] Missing dashed underline after section ("Parameters"
|
|||
531 532 | """
|
||||
532 533 |
|
||||
|
||||
sections.py:548:5: D407 [*] Missing dashed underline after section ("Args")
|
||||
|
|
||||
547 | def lowercase_sub_section_header():
|
||||
548 | """Below, `returns:` should _not_ be considered a section header.
|
||||
| _____^
|
||||
549 | |
|
||||
550 | | Args:
|
||||
551 | | Here's a note.
|
||||
552 | |
|
||||
553 | | returns:
|
||||
554 | | """
|
||||
| |_______^ D407
|
||||
|
|
||||
= help: Add dashed line under "Args"
|
||||
|
||||
ℹ Safe fix
|
||||
548 548 | """Below, `returns:` should _not_ be considered a section header.
|
||||
549 549 |
|
||||
550 550 | Args:
|
||||
551 |+ ----
|
||||
551 552 | Here's a note.
|
||||
552 553 |
|
||||
553 554 | returns:
|
||||
|
||||
sections.py:558:5: D407 [*] Missing dashed underline after section ("Args")
|
||||
|
|
||||
557 | def titlecase_sub_section_header():
|
||||
558 | """Below, `Returns:` should be considered a section header.
|
||||
| _____^
|
||||
559 | |
|
||||
560 | | Args:
|
||||
561 | | Here's a note.
|
||||
562 | |
|
||||
563 | | Returns:
|
||||
564 | | """
|
||||
| |_______^ D407
|
||||
|
|
||||
= help: Add dashed line under "Args"
|
||||
|
||||
ℹ Safe fix
|
||||
558 558 | """Below, `Returns:` should be considered a section header.
|
||||
559 559 |
|
||||
560 560 | Args:
|
||||
561 |+ ----
|
||||
561 562 | Here's a note.
|
||||
562 563 |
|
||||
563 564 | Returns:
|
||||
|
||||
sections.py:558:5: D407 [*] Missing dashed underline after section ("Returns")
|
||||
|
|
||||
557 | def titlecase_sub_section_header():
|
||||
558 | """Below, `Returns:` should be considered a section header.
|
||||
| _____^
|
||||
559 | |
|
||||
560 | | Args:
|
||||
561 | | Here's a note.
|
||||
562 | |
|
||||
563 | | Returns:
|
||||
564 | | """
|
||||
| |_______^ D407
|
||||
|
|
||||
= help: Add dashed line under "Returns"
|
||||
|
||||
ℹ Safe fix
|
||||
561 561 | Here's a note.
|
||||
562 562 |
|
||||
563 563 | Returns:
|
||||
564 |+ -------
|
||||
564 565 | """
|
||||
|
||||
|
||||
|
|
|
@ -97,4 +97,18 @@ sections.py:261:5: D414 Section has no content ("Returns")
|
|||
| |_______^ D414
|
||||
|
|
||||
|
||||
sections.py:558:5: D414 Section has no content ("Returns")
|
||||
|
|
||||
557 | def titlecase_sub_section_header():
|
||||
558 | """Below, `Returns:` should be considered a section header.
|
||||
| _____^
|
||||
559 | |
|
||||
560 | | Args:
|
||||
561 | | Here's a note.
|
||||
562 | |
|
||||
563 | | Returns:
|
||||
564 | | """
|
||||
| |_______^ D414
|
||||
|
|
||||
|
||||
|
||||
|
|
|
@ -64,4 +64,12 @@ D417.py:108:5: D417 Missing argument description in the docstring for `f`: `*arg
|
|||
109 | """Do something.
|
||||
|
|
||||
|
||||
D417.py:155:5: D417 Missing argument description in the docstring for `select_data`: `auto_save`
|
||||
|
|
||||
155 | def select_data(
|
||||
| ^^^^^^^^^^^ D417
|
||||
156 | query: str,
|
||||
157 | args: tuple,
|
||||
|
|
||||
|
||||
|
||||
|
|
|
@ -64,4 +64,12 @@ D417.py:108:5: D417 Missing argument description in the docstring for `f`: `*arg
|
|||
109 | """Do something.
|
||||
|
|
||||
|
||||
D417.py:155:5: D417 Missing argument description in the docstring for `select_data`: `auto_save`
|
||||
|
|
||||
155 | def select_data(
|
||||
| ^^^^^^^^^^^ D417
|
||||
156 | query: str,
|
||||
157 | args: tuple,
|
||||
|
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue