Skip to content

Use docstring_parser.description for help (fix #469)#470

Open
rec wants to merge 1 commit into
brentyi:mainfrom
rec:main
Open

Use docstring_parser.description for help (fix #469)#470
rec wants to merge 1 commit into
brentyi:mainfrom
rec:main

Conversation

@rec
Copy link
Copy Markdown

@rec rec commented May 14, 2026

I accidentally closed the linked issue. 🙂

Comment thread src/tyro/_docstrings.py
if docstring is None:
return ""

docstring = _strings.dedent(docstring)
Copy link
Copy Markdown
Author

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!

Comment thread src/tyro/_docstrings.py
if parsed_docstring.long_description is not None:
parts.append(parsed_docstring.long_description)
return "\n".join(parts)
return docstring_parser.parse(docstring).description
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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 docstring_parser does.

Comment thread tests/test_helptext.py

usage, *lines = get_helptext_with_checks(Helptext).split("\n")
assert usage.startswith("usage:")
assert lines[:7] == ["", "First", "", "Second", "", "Third", ""]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this commit, this code would have read:

assert lines[:5] == ["", "First Second", "", "Third", ""]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant