-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Extra table rows for Returns
when empty lines start with spaces
#129
Comments
Found the "culprit"... By placing a {
"docstring": "<griffe.dataclasses.Docstring object at 0x00000219C5854AC0>",
"ignore_init_summary": false,
"trim_doctest_flags": true,
"options": {
"ignore_init_summary": false,
"trim_doctest_flags": true
},
"sections": [
"<griffe.docstrings.dataclasses.DocstringSectionText object at 0x00000219C5873160>",
"<griffe.docstrings.dataclasses.DocstringSectionReturns object at 0x00000219C5880A60>",
"<griffe.docstrings.dataclasses.DocstringSectionAdmonition object at 0x00000219C5880DC0>"
],
"current_section": [],
"in_code_block": false,
"lines": [
"Test docstring with 2 extra empty parameters.",
"",
"Returns:",
" str: TEST",
" ",
" ",
"Example:",
" ```pycon",
" >>> test()",
" ```"
],
"ignore_summary": false,
"offset": 10,
"line_lower": "example:",
"match": "<re.Match object; span=(0, 8), match='Example: '>",
"groups": {
"type": "Example",
"title": null
},
"title": "Example",
"admonition_type": "example",
"reader": "<function _read_returns_section at 0x00000219C5744E50>",
"section": "<griffe.docstrings.dataclasses.DocstringSectionReturns object at 0x00000219C5880A60>",
"contents": "```pycon\n>>> test()\n```"
} As we can see the I think the {
[...]
"lines": [
"Test docstring with 2 extra empty parameters.",
"",
"Returns:",
" str: TEST",
"",
"Example:",
" ```pycon",
" >>> test()",
" ```"
]
[...]
} The griffe/src/griffe/dataclasses.py Lines 126 to 133 in 1ff0918
Do you think that maybe we should normalize all empty lines by removing extra whitespace characters (regex: UPDATEI tried adding griffe/src/griffe/docstrings/google.py Line 631 in 1ff0918
|
Solution (?)I made some progress... I found that the filtering on I solved temporarily by changing this line: griffe/src/griffe/docstrings/google.py Line 393 in 1ff0918
To: if name is not None:
returns.append(DocstringReturn(name=name or "", annotation=annotation, description=description)) Considerations
|
Hello, thanks for the report and investigation! I've looked at it and the bug actually comes from the function that splits blocks of text (sections). If you look at this: griffe/src/griffe/docstrings/google.py Lines 112 to 119 in 1ff0918
...you might notice that the first condition does not check if the line is "empty" (just whitespace). So the solution would simply be to check that, and update the rest of the checks accordingly. I should be able to push a fix tonight 🙂 |
Thank you @pawamoy for the quick fix! Do you know when will this fix be available in a release? |
Just released 0.25.5 🙂 |
Describe the bug
When there are lines in the docstring that are not completely empty (but have spaces or tabs in it) between the end of the
Returns
block and the next block (in my caseExample
) extra table rows are added.To Reproduce
Steps to reproduce the behavior:
This however does not happen if there are no spaces (only empty lines) between the last parameter and the next block (in this case
Example
)System information
griffe
version:0.25.4
3.9
The text was updated successfully, but these errors were encountered: