Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ def _get_kwargs(self):
'default',
'type',
'choices',
'required',
'help',
'metavar',
]
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4873,12 +4873,13 @@ def test_optional(self):
nargs='+',
default=42,
choices=[1, 2, 3],
required=False,
help='HELP',
metavar='METAVAR')
string = (
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
"nargs='+', const=None, default=42, type='int', "
"choices=[1, 2, 3], help='HELP', metavar='METAVAR')")
"choices=[1, 2, 3], required=False, help='HELP', metavar='METAVAR')")
self.assertStringEqual(option, string)

def test_argument(self):
Expand All @@ -4889,12 +4890,13 @@ def test_argument(self):
nargs='?',
default=2.5,
choices=[0.5, 1.5, 2.5],
required=True,
help='H HH H',
metavar='MV MV MV')
string = (
"Action(option_strings=[], dest='x', nargs='?', "
"const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], "
"help='H HH H', metavar='MV MV MV')" % float)
"required=True, help='H HH H', metavar='MV MV MV')" % float)
self.assertStringEqual(argument, string)

def test_namespace(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``required`` attribute to :class:`argparse.Action` repr output.