Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3931d8a

Browse files
rindeallocalhost
authored and
localhost
committed
argparse: use str() consistently and explicitly to print choices
Signed-off-by: Jan Chren (rindeal) <dev.rindeal@gmail.com>
1 parent73906d5 commit3931d8a

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

‎Lib/argparse.py‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,7 @@ def _metavar_formatter(self, action, default_metavar):
584584
ifaction.metavarisnotNone:
585585
result=action.metavar
586586
elifaction.choicesisnotNone:
587-
choice_strs= [str(choice)forchoiceinaction.choices]
588-
result='{%s}'%','.join(choice_strs)
587+
result='{%s}'%','.join(map(str,action.choices))
589588
else:
590589
result=default_metavar
591590

@@ -633,8 +632,7 @@ def _expand_help(self, action):
633632
ifhasattr(params[name],'__name__'):
634633
params[name]=params[name].__name__
635634
ifparams.get('choices')isnotNone:
636-
choices_str=', '.join([str(c)forcinparams['choices']])
637-
params['choices']=choices_str
635+
params['choices']=', '.join(map(str,params['choices']))
638636
returnself._get_help_string(action)%params
639637

640638
def_iter_indented_subactions(self,action):
@@ -743,7 +741,7 @@ def _get_action_name(argument):
743741
elifargument.destnotin (None,SUPPRESS):
744742
returnargument.dest
745743
elifargument.choices:
746-
return'{'+','.join(argument.choices)+'}'
744+
return'{%s}'%','.join(map(str,argument.choices))
747745
else:
748746
returnNone
749747

@@ -2613,7 +2611,7 @@ def _check_value(self, action, value):
26132611
# converted value must be one of the choices (if specified)
26142612
ifaction.choicesisnotNoneandvaluenotinaction.choices:
26152613
args= {'value':value,
2616-
'choices':', '.join(map(repr,action.choices))}
2614+
'choices':', '.join(map(str,action.choices))}
26172615
msg=_('invalid choice: %(value)r (choose from %(choices)s)')
26182616
raiseArgumentError(action,msg%args)
26192617

‎Lib/test/test_argparse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2361,7 +2361,7 @@ def test_wrong_argument_subparsers_no_destination_error(self):
23612361
parser.parse_args(('baz',))
23622362
self.assertRegex(
23632363
excinfo.exception.stderr,
2364-
r"error: argument {foo,bar}: invalid choice: 'baz' \(choose from'foo', 'bar'\)\n$"
2364+
r"error: argument {foo,bar}: invalid choice: 'baz' \(choose from foo,bar\)\n$"
23652365
)
23662366

23672367
deftest_optional_subparsers(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp