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

Commit11652ce

Browse files
gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)
GH- Adding 'required' to names in Lib.argparse.Actiongh-91832:Added 'required' to the list `names` in `Lib.argparse.Action`.Changed constant strings that test the Action object.Automerge-Triggered-By: GH:merwok(cherry picked from commit4ed3900)Co-authored-by: Abhigyan Bose <abhigyandeepbose@gmail.com>
1 parente25799d commit11652ce

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

‎Lib/argparse.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ def _get_kwargs(self):
848848
'default',
849849
'type',
850850
'choices',
851+
'required',
851852
'help',
852853
'metavar',
853854
]

‎Lib/test/test_argparse.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4873,12 +4873,13 @@ def test_optional(self):
48734873
nargs='+',
48744874
default=42,
48754875
choices=[1,2,3],
4876+
required=False,
48764877
help='HELP',
48774878
metavar='METAVAR')
48784879
string= (
48794880
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
48804881
"nargs='+', const=None, default=42, type='int', "
4881-
"choices=[1, 2, 3], help='HELP', metavar='METAVAR')")
4882+
"choices=[1, 2, 3],required=False,help='HELP', metavar='METAVAR')")
48824883
self.assertStringEqual(option,string)
48834884

48844885
deftest_argument(self):
@@ -4889,12 +4890,13 @@ def test_argument(self):
48894890
nargs='?',
48904891
default=2.5,
48914892
choices=[0.5,1.5,2.5],
4893+
required=True,
48924894
help='H HH H',
48934895
metavar='MV MV MV')
48944896
string= (
48954897
"Action(option_strings=[], dest='x', nargs='?', "
48964898
"const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], "
4897-
"help='H HH H', metavar='MV MV MV')"%float)
4899+
"required=True,help='H HH H', metavar='MV MV MV')"%float)
48984900
self.assertStringEqual(argument,string)
48994901

49004902
deftest_namespace(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``required`` attribute to:class:`argparse.Action` repr output.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp