Repository navigation
Escape '%' in help text taken from comments and docstrings - #376
Open
Mykhailo-Romanov-AMZ wants to merge 1 commit into
Open
Mykhailo-Romanov-AMZ wants to merge 1 commit into
Mykhailo-Romanov-AMZ wants to merge 1 commit into
Conversation
argparse treats `help` as a %-format string, so a literal '%' in a field's comment or docstring (e.g. "Retry about 5% of requests.") made `--help` raise a TypeError. Escape '%' as '%%' when the help comes from a comment or docstring. Explicit `help=` strings are left unchanged, so `%(default)s` still works there. Fixes lebrice#372
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi! I'm Mykhailo, a first-time contributor. Thanks for maintaining SimpleParsing.
What does this PR do?
Fixes #372 by escaping
%as%%in help text taken from a field's comment or docstring, so argparse prints it literally. Explicitfield(help=...)strings are unchanged, so%(default)sstill works there.How was this tested?
test_help_from_docstring_with_percent_signto cover%in a comment above, a docstring below and an inline comment, plus an explicithelp=control. It fails onmasterwith theTypeErrorfrom the issue and passes with the fix.uv run pytest --benchmark-disable test/test_docstrings.py(10 passed).pre-commit runon the changed files passes.Diff Summary
simple_parsing/wrappers/field_wrapper.py: escape%in comment/docstring help inget_arg_options.test/test_docstrings.py: added reproduction test.Prepared with AI assistance; I reviewed and verified it locally.