Skip to content

Commit 9b7421e

Browse files
committed
Fix formatting of empty-string default values
1 parent edadcad commit 9b7421e

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Change log
33
**********
44

5+
* Fix formatting of empty-string default values.
6+
Patch by Adam Turner.
7+
58
0.5.1
69
#####
710

sphinxarg/ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def render_list(l, markdown_help, settings=None):
8787
return all_children
8888

8989

90-
def _is_suppressed(item):
90+
def _is_suppressed(item: str | None) -> bool:
9191
"""Return whether item should not be printed."""
9292
if item is None:
9393
return True

sphinxarg/parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def parse_parser(parser, data=None, **kwargs):
119119
# Quote default values for string/None types
120120
default = action.default
121121
if (
122-
action.default not in ['', None, True, False]
123-
and action.type in [None, str]
124-
and isinstance(action.default, str)
122+
default is not None
123+
and not isinstance(default, bool)
124+
and action.type in {None, str}
125+
and isinstance(default, str)
125126
):
126127
default = f"'{default}'"
127128

test/sample-directive-special.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ def get_parser():
2424
default=['*.rst', '_txt_', '**strong**', '*italic*', '``code``'],
2525
nargs='+',
2626
)
27+
parser.add_argument(
28+
'--some-text-empty-default',
29+
help='Scalar text input',
30+
default='',
31+
)
2732

2833
return parser

0 commit comments

Comments
 (0)