Skip to content

Commit

Permalink
Fix % in docstrings, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Jan 2, 2022
1 parent 311a66b commit d5da406
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions dcargs/_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def _generate_helptext(arg: ArgumentDefinition) -> _ArgumentTransformOutput:
arg.parent_class, arg.field.name
)
if docstring_help is not None:
# Note that the percent symbol needs some extra handling in argparse.
# https://stackoverflow.com/questions/21168120/python-argparse-errors-with-in-help-string
docstring_help = docstring_help.replace("%", "%%")
help_parts.append(docstring_help)

if arg.default is not None and hasattr(arg.default, "name"):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="dcargs",
version="0.0.9",
version="0.0.10",
description="Portable, reusable, strongly typed CLIs from dataclass definitions",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
7 changes: 5 additions & 2 deletions tests/test_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,19 @@ class HelptextHardString:
x: str = (
"This docstring may be tougher to parse!"
)
"""Helptext."""
"""Helptext. 2% milk."""
# fmt: on

# Note that the percent symbol needs some extra handling in argparse.
# https://stackoverflow.com/questions/21168120/python-argparse-errors-with-in-help-string

f = io.StringIO()
with pytest.raises(SystemExit):
with contextlib.redirect_stdout(f):
dcargs.parse(HelptextHardString, args=["--help"])
helptext = f.getvalue()
assert (
"--x STR Helptext. (default: This docstring may be tougher to parse!)\n"
"--x STR Helptext. 2% milk. (default: This docstring may be tougher to parse!)\n"
in helptext
)

Expand Down

0 comments on commit d5da406

Please sign in to comment.