File tree Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Expand file tree Collapse file tree 3 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 14
14
15
15
### Fixes
16
16
- [ GH-152 ] ( https://github.com/hamdanal/rich-argparse/issues/152 ) ,
17
- [ PR-153] ( https://github.com/hamdanal/rich-argparse/pull/153 )
17
+ [ PR-153] ( https://github.com/hamdanal/rich-argparse/pull/153 ) ,
18
+ [ PR-154] ( https://github.com/hamdanal/rich-argparse/pull/154 )
18
19
Fix ` ValueError ` when using ` %(default)s ` inside square brackets and ` help_markup ` is enabled.
19
20
- [ GH-141 ] ( https://github.com/hamdanal/rich-argparse/issues/141 ) ,
20
21
[ PR-142] ( https://github.com/hamdanal/rich-argparse/pull/142 )
Original file line number Diff line number Diff line change @@ -452,13 +452,14 @@ def _rich_expand_help(self, action: Action) -> r.Text:
452
452
import warnings
453
453
454
454
action_id = next (iter (action .option_strings ), action .dest )
455
- md = re .search (
456
- rf"\[([^\]]*{ self ._printf_style_pattern .pattern } [^\]]*)\]" , help_string , re .X
457
- )
458
- repl = (
459
- repr (md .group (1 ))[1 :- 1 ]
460
- if md and md .group ("mapping" ) == "default"
461
- else "default: %(default)s"
455
+ printf_pat = self ._printf_style_pattern .pattern
456
+ repl = next (
457
+ (
458
+ repr (m .group (1 ))[1 :- 1 ]
459
+ for m in re .finditer (rf"\[([^\]]*{ printf_pat } [^\]]*)\]" , help_string , re .X )
460
+ if m .group ("mapping" ) == "default"
461
+ ),
462
+ "default: %(default)s" , # pragma: >=3.9 cover # fails on Python 3.8!
462
463
)
463
464
msg = (
464
465
f"Failed to process default value in help string of argument { action_id !r} ."
Original file line number Diff line number Diff line change @@ -1028,23 +1028,23 @@ def test_arg_default_in_markup():
1028
1028
"--foo" ,
1029
1029
default = "def" ,
1030
1030
help = (
1031
- "(default : %(default)r)[default wrong : %(default)r] text [default wrong : %(default)s]"
1032
- "(default : %(default)s) [link default wrong %(default)s] %(default)s"
1031
+ "[%(type)r type](good : %(default)r)[bad : %(default)r] text [bad : %(default)s]"
1032
+ "(good : %(default)s) [link bad %(default)s] %(default)s"
1033
1033
),
1034
1034
)
1035
1035
expected_help_text = """\
1036
1036
Usage: PROG [-h] [--foo FOO]
1037
1037
1038
1038
Optional Arguments:
1039
1039
-h, --help show this help message and exit
1040
- --foo FOO (default : 'def') text (default : def) def
1040
+ --foo FOO [None type](good : 'def') text (good : def) def
1041
1041
"""
1042
1042
with pytest .warns (
1043
1043
UserWarning ,
1044
1044
match = re .escape (
1045
1045
"Failed to process default value in help string of argument '--foo'.\n "
1046
1046
"Hint: try disabling rich markup: `RichHelpFormatter.help_markup = False`\n "
1047
- " or replace brackets by parenthesis: `[default wrong : %(default)r]` -> `(default wrong : %(default)r)`"
1047
+ " or replace brackets by parenthesis: `[bad : %(default)r]` -> `(bad : %(default)r)`"
1048
1048
),
1049
1049
):
1050
1050
help_text = parser .format_help ()
You can’t perform that action at this time.
0 commit comments