]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)
authorAbhigyan Bose <abhigyandeepbose@gmail.com>
Thu, 28 Apr 2022 14:50:27 +0000 (20:20 +0530)
committerGitHub <noreply@github.com>
Thu, 28 Apr 2022 14:50:27 +0000 (07:50 -0700)
# 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
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst [new file with mode: 0644]

index 429a72ab7841e787438286304bff6a084e351b64..668e1d416231fce19a6a2b68b60ac0f556755cec 100644 (file)
@@ -850,6 +850,7 @@ class Action(_AttributeHolder):
             'default',
             'type',
             'choices',
+            'required',
             'help',
             'metavar',
         ]
index fd107faee47658fbd57ade69f46185aa078a235f..5777cb50f7e5392979bf9e6aba1e5c2af3c5fb9a 100644 (file)
@@ -4900,12 +4900,13 @@ class TestStrings(TestCase):
             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):
@@ -4916,12 +4917,13 @@ class TestStrings(TestCase):
             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):
diff --git a/Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst b/Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst
new file mode 100644 (file)
index 0000000..0ebf773
--- /dev/null
@@ -0,0 +1 @@
+Add ``required`` attribute to :class:`argparse.Action` repr output.