-
Notifications
You must be signed in to change notification settings - Fork 47
Use docstring_parser.description for help (fix #469) #470
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,20 +364,11 @@ def get_callable_description(f: Callable) -> str: | |
| if docstring is None: | ||
| return "" | ||
|
|
||
| docstring = _strings.dedent(docstring) | ||
|
|
||
| if dataclasses.is_dataclass(f): | ||
| default_doc = f.__name__ + str(inspect.signature(f)).replace(" -> None", "") # type: ignore | ||
| if docstring == default_doc: | ||
| return "" | ||
|
|
||
| import docstring_parser | ||
|
|
||
| parsed_docstring = docstring_parser.parse(docstring) | ||
|
|
||
| parts: List[str] = [] | ||
| if parsed_docstring.short_description is not None: | ||
| parts.append(parsed_docstring.short_description) | ||
| if parsed_docstring.long_description is not None: | ||
| parts.append(parsed_docstring.long_description) | ||
| return "\n".join(parts) | ||
| return docstring_parser.parse(docstring).description | ||
|
Author
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. This one line does the same as the above, except it doesn't remove the carriage return between the first and second paragraphs. It's also conceptually simpler to do exactly what |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,22 @@ class Helptext: | |
| assert "Documentation 3 (default: 3)" in helptext | ||
|
|
||
|
|
||
| def test_helptext_paragraphs() -> None: | ||
| @dataclasses.dataclass | ||
| class Helptext: | ||
| """ | ||
| First | ||
|
|
||
| Second | ||
|
|
||
| Third | ||
| """ | ||
|
|
||
| usage, *lines = get_helptext_with_checks(Helptext).split("\n") | ||
| assert usage.startswith("usage:") | ||
| assert lines[:7] == ["", "First", "", "Second", "", "Third", ""] | ||
|
Author
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. Before this commit, this code would have read: |
||
|
|
||
|
|
||
| def test_helptext_sphinx_autodoc_style() -> None: | ||
| @dataclasses.dataclass | ||
| class Helptext: | ||
|
|
||
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.
PEP-257 guarantees that this step is not necessary!