-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[pydocstyle] Skip section detection inside RST directive bodies (D214, D405, D413)
#23635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ntBre
merged 5 commits into
astral-sh:main
from
bxff:investigate/sphinx-docstring-reformat
Jul 28, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5e3097a
[`pydocstyle`] Skip section detection inside RST directive bodies (`D…
bxff 5b14368
fix(pydocstyle): track nested rst directives
bxff b746d9a
test(pydocstyle): normalize sphinx directive snapshot
bxff 713e65a
Merge branch 'main' into HEAD
ntBre 0707fce
simplify
ntBre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
crates/ruff_linter/resources/test/fixtures/pydocstyle/sphinx_directive.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| """A module-level docstring with a Sphinx directive containing section-like content. | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| references: | ||
| - ref: Bibliographic citation in your favorite format. | ||
| refType: open literature | ||
|
|
||
| This is more text after the directive. | ||
| """ | ||
|
|
||
|
|
||
| def func(): | ||
| """A function-level docstring with a Sphinx directive. | ||
|
|
||
| Examples: | ||
| This is an example. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| returns = "not a section" | ||
| notes = "also not a section" | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
|
|
||
|
|
||
| def func2(): | ||
| """A function-level docstring with single-colon directive (invalid RST but still common). | ||
|
|
||
| .. code-block: yaml | ||
|
|
||
| references: | ||
| - ref: Some reference. | ||
|
|
||
| More text. | ||
| """ | ||
|
|
||
|
|
||
| def func3(): | ||
| """A function-level docstring with nested directives. | ||
|
|
||
| .. note:: | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| warnings = "not a section" | ||
|
|
||
| Returns: | ||
| None | ||
| """ | ||
|
|
||
|
|
||
| def func4(): | ||
| """A function-level docstring where a real section follows a directive. | ||
|
|
||
| .. code-block:: python | ||
|
|
||
| example = "code" | ||
|
|
||
| Notes: | ||
| This IS a real section and should still be detected. | ||
| """ | ||
| # Regression test for nested directive state. | ||
| def func5(): | ||
| """A nested directive whose outer body contains section-like content. | ||
|
|
||
| .. note:: | ||
|
|
||
| .. code-block:: yaml | ||
|
|
||
| references: | ||
| - ref: Some reference. | ||
|
|
||
| references: | ||
| Still part of the note body, not a section. | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D214_sphinx_directive.py.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/pydocstyle/mod.rs | ||
| --- | ||
|
|
4 changes: 4 additions & 0 deletions
4
...pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D405_sphinx_directive.py.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/pydocstyle/mod.rs | ||
| --- | ||
|
|
53 changes: 53 additions & 0 deletions
53
...pydocstyle/snapshots/ruff_linter__rules__pydocstyle__tests__D413_sphinx_directive.py.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/pydocstyle/mod.rs | ||
| --- | ||
| D413 [*] Missing blank line after last section ("Returns") | ||
| --> sphinx_directive.py:24:5 | ||
| | | ||
| 22 | notes = "also not a section" | ||
| 23 | | ||
| 24 | Returns: | ||
| | ^^^^^^^ | ||
| 25 | None | ||
| 26 | """ | ||
| | | ||
| help: Add blank line after "Returns" | ||
| | | ||
| 25 | None | ||
| 26 + | ||
| 27 | """ | ||
| | | ||
|
|
||
| D413 [*] Missing blank line after last section ("Returns") | ||
| --> sphinx_directive.py:50:5 | ||
| | | ||
| 48 | warnings = "not a section" | ||
| 49 | | ||
| 50 | Returns: | ||
| | ^^^^^^^ | ||
| 51 | None | ||
| 52 | """ | ||
| | | ||
| help: Add blank line after "Returns" | ||
| | | ||
| 51 | None | ||
| 52 + | ||
| 53 | """ | ||
| | | ||
|
|
||
| D413 [*] Missing blank line after last section ("Notes") | ||
| --> sphinx_directive.py:62:5 | ||
| | | ||
| 60 | example = "code" | ||
| 61 | | ||
| 62 | Notes: | ||
| | ^^^^^ | ||
| 63 | This IS a real section and should still be detected. | ||
| 64 | """ | ||
| | | ||
| help: Add blank line after "Notes" | ||
| | | ||
| 63 | This IS a real section and should still be detected. | ||
| 64 + | ||
| 65 | """ | ||
| | |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.