mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)
GH- 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
(cherry picked from commit 4ed3900041
)
Co-authored-by: Abhigyan Bose <abhigyandeepbose@gmail.com>
This commit is contained in:
parent
e25799d27d
commit
11652ceccf
3 changed files with 6 additions and 2 deletions
|
@ -848,6 +848,7 @@ class Action(_AttributeHolder):
|
||||||
'default',
|
'default',
|
||||||
'type',
|
'type',
|
||||||
'choices',
|
'choices',
|
||||||
|
'required',
|
||||||
'help',
|
'help',
|
||||||
'metavar',
|
'metavar',
|
||||||
]
|
]
|
||||||
|
|
|
@ -4873,12 +4873,13 @@ class TestStrings(TestCase):
|
||||||
nargs='+',
|
nargs='+',
|
||||||
default=42,
|
default=42,
|
||||||
choices=[1, 2, 3],
|
choices=[1, 2, 3],
|
||||||
|
required=False,
|
||||||
help='HELP',
|
help='HELP',
|
||||||
metavar='METAVAR')
|
metavar='METAVAR')
|
||||||
string = (
|
string = (
|
||||||
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
|
"Action(option_strings=['--foo', '-a', '-b'], dest='b', "
|
||||||
"nargs='+', const=None, default=42, type='int', "
|
"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)
|
self.assertStringEqual(option, string)
|
||||||
|
|
||||||
def test_argument(self):
|
def test_argument(self):
|
||||||
|
@ -4889,12 +4890,13 @@ class TestStrings(TestCase):
|
||||||
nargs='?',
|
nargs='?',
|
||||||
default=2.5,
|
default=2.5,
|
||||||
choices=[0.5, 1.5, 2.5],
|
choices=[0.5, 1.5, 2.5],
|
||||||
|
required=True,
|
||||||
help='H HH H',
|
help='H HH H',
|
||||||
metavar='MV MV MV')
|
metavar='MV MV MV')
|
||||||
string = (
|
string = (
|
||||||
"Action(option_strings=[], dest='x', nargs='?', "
|
"Action(option_strings=[], dest='x', nargs='?', "
|
||||||
"const=None, default=2.5, type=%r, choices=[0.5, 1.5, 2.5], "
|
"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)
|
self.assertStringEqual(argument, string)
|
||||||
|
|
||||||
def test_namespace(self):
|
def test_namespace(self):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add ``required`` attribute to :class:`argparse.Action` repr output.
|
Loading…
Add table
Add a link
Reference in a new issue