-
Notifications
You must be signed in to change notification settings - Fork 54
Additional missing sections for Google-style docstrings #108
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
Open
BrianPugh
wants to merge
2
commits into
rr-:master
Choose a base branch
from
BrianPugh:additional-google-sections
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+211
−2
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1001,3 +1001,165 @@ def test_compose_expanded(source: str, expected: str) -> None: | |
| compose(parse(source), rendering_style=RenderingStyle.EXPANDED) | ||
| == expected | ||
| ) | ||
|
|
||
|
|
||
| def test_notes_section() -> None: | ||
| """Test parsing a Notes section.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| Notes: | ||
| This is important. | ||
| Second line. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert len(docstring.meta) == 1 | ||
| assert docstring.meta[0].args == ["notes"] | ||
| assert docstring.meta[0].description == "This is important.\nSecond line." | ||
|
|
||
|
|
||
| def test_warnings_section() -> None: | ||
| """Test parsing a Warnings section.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| Warnings: | ||
| Be careful with this. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert len(docstring.meta) == 1 | ||
| assert docstring.meta[0].args == ["warnings"] | ||
| assert docstring.meta[0].description == "Be careful with this." | ||
|
|
||
|
|
||
| def test_see_also_section() -> None: | ||
| """Test parsing a See Also section.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| See Also: | ||
| bar: related function. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert len(docstring.meta) == 1 | ||
| assert docstring.meta[0].args == ["see_also"] | ||
| assert docstring.meta[0].description == "bar: related function." | ||
|
|
||
|
|
||
| def test_references_section() -> None: | ||
| """Test parsing a References section.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| References: | ||
| Some paper (2024). | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert len(docstring.meta) == 1 | ||
| assert docstring.meta[0].args == ["references"] | ||
| assert docstring.meta[0].description == "Some paper (2024)." | ||
|
|
||
|
|
||
| def test_deprecated_section() -> None: | ||
| """Test parsing a Deprecated section with version.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| Deprecated: | ||
| 1.6.0 | ||
| Use new_function instead. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert docstring.deprecation is not None | ||
| assert docstring.deprecation.version == "1.6.0" | ||
| assert docstring.deprecation.description == "Use new_function instead." | ||
|
|
||
|
|
||
| def test_deprecated_section_no_version() -> None: | ||
| """Test parsing a Deprecated section without version.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| Deprecated: | ||
| Use new_function instead. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert docstring.deprecation is not None | ||
| assert docstring.deprecation.version == "Use new_function instead." | ||
| assert docstring.deprecation.description is None | ||
|
Comment on lines
+1100
to
+1101
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Description being |
||
|
|
||
|
|
||
| def test_notes_with_other_sections() -> None: | ||
| """Test Notes coexists with Args and Returns.""" | ||
| docstring = parse( | ||
| """ | ||
| Short description | ||
|
|
||
| Args: | ||
| arg1 (int): first arg | ||
|
|
||
| Returns: | ||
| str: a value | ||
|
|
||
| Notes: | ||
| This is important. | ||
| """ | ||
| ) | ||
| assert docstring.short_description == "Short description" | ||
| assert len(docstring.params) == 1 | ||
| assert docstring.params[0].arg_name == "arg1" | ||
| assert docstring.returns is not None | ||
| assert docstring.returns.type_name == "str" | ||
| notes = [m for m in docstring.meta if m.args == ["notes"]] | ||
| assert len(notes) == 1 | ||
| assert notes[0].description == "This is important." | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "source, expected_key", | ||
| [ | ||
| ("Note:\n a note", "notes"), | ||
| ("Notes:\n a note", "notes"), | ||
| ("Warning:\n be careful", "warnings"), | ||
| ("Warnings:\n be careful", "warnings"), | ||
| ("Reference:\n some ref", "references"), | ||
| ("References:\n some ref", "references"), | ||
| ("Related:\n see bar", "see_also"), | ||
| ("See Also:\n see bar", "see_also"), | ||
| ], | ||
| ) | ||
| def test_singular_aliases(source: str, expected_key: str) -> None: | ||
| """Test that singular/plural aliases map to the same key.""" | ||
| docstring = parse(f"Short description\n\n{source}") | ||
| assert len(docstring.meta) == 1 | ||
| assert docstring.meta[0].args == [expected_key] | ||
|
|
||
|
|
||
| def test_notes_compose_round_trip() -> None: | ||
| """Test that a Notes section survives a parse-compose-parse cycle.""" | ||
| original = """Short description | ||
|
|
||
| Notes: | ||
| This is important. | ||
| Second line.""" | ||
| docstring1 = parse(original) | ||
| composed = compose(docstring1) | ||
| docstring2 = parse(composed) | ||
|
|
||
| notes1 = [m for m in docstring1.meta if m.args == ["notes"]] | ||
| notes2 = [m for m in docstring2.meta if m.args == ["notes"]] | ||
| assert len(notes1) == 1 | ||
| assert len(notes2) == 1 | ||
| assert notes1[0].description == notes2[0].description | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a parametrize case to the
test_compose()test to make sure that aSee Also:gets composed correctly.