Skip to content

Commit

Permalink
Fix formatting of empty-string default values
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 17, 2024
1 parent edadcad commit 9b7421e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Change log
**********

* Fix formatting of empty-string default values.
Patch by Adam Turner.

0.5.1
#####

Expand Down
2 changes: 1 addition & 1 deletion sphinxarg/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def render_list(l, markdown_help, settings=None):
return all_children


def _is_suppressed(item):
def _is_suppressed(item: str | None) -> bool:
"""Return whether item should not be printed."""
if item is None:
return True
Expand Down
7 changes: 4 additions & 3 deletions sphinxarg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ def parse_parser(parser, data=None, **kwargs):
# Quote default values for string/None types
default = action.default
if (
action.default not in ['', None, True, False]
and action.type in [None, str]
and isinstance(action.default, str)
default is not None
and not isinstance(default, bool)
and action.type in {None, str}
and isinstance(default, str)
):
default = f"'{default}'"

Expand Down
5 changes: 5 additions & 0 deletions test/sample-directive-special.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ def get_parser():
default=['*.rst', '_txt_', '**strong**', '*italic*', '``code``'],
nargs='+',
)
parser.add_argument(
'--some-text-empty-default',
help='Scalar text input',
default='',
)

return parser

0 comments on commit 9b7421e

Please sign in to comment.