Skip to content

Commit 4ed3900

Browse files
authored
gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)
# Adding 'required' to names in Lib.argparse.Action gh-91832: Added 'required' to the list `names` in `Lib.argparse.Action`. Changed constant strings that test the Action object. Automerge-Triggered-By: GH:merwok
1 parent 6dcbc08 commit 4ed3900

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

Lib/argparse.py

+1
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ def _get_kwargs(self):
850850
'default',
851851
'type',
852852
'choices',
853+
'required',
853854
'help',
854855
'metavar',
855856
]

Lib/test/test_argparse.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -4900,12 +4900,13 @@ def test_optional(self):
49004900
nargs='+',
49014901
default=42,
49024902
choices=[1, 2, 3],
4903+
required=False,
49034904
help='HELP',
49044905
metavar='METAVAR')
49054906
string = (
49064907
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
49074908
"nargs='+', const=None, default=42, type='int', "
4908-
"choices=[1, 2, 3], help='HELP', metavar='METAVAR')")
4909+
"choices=[1, 2, 3], required=False, help='HELP', metavar='METAVAR')")
49094910
self.assertStringEqual(option, string)
49104911

49114912
def test_argument(self):
@@ -4916,12 +4917,13 @@ def test_argument(self):
49164917
nargs='?',
49174918
default=2.5,
49184919
choices=[0.5, 1.5, 2.5],
4920+
required=True,
49194921
help='H HH H',
49204922
metavar='MV MV MV')
49214923
string = (
49224924
"Action(option_strings=[], dest='x', nargs='?', "
49234925
"const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], "
4924-
"help='H HH H', metavar='MV MV MV')" % float)
4926+
"required=True, help='H HH H', metavar='MV MV MV')" % float)
49254927
self.assertStringEqual(argument, string)
49264928

49274929
def test_namespace(self):
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)