]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91832: Add 'required' attr to argparse.Action repr (GH-91841)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 28 Apr 2022 15:19:07 +0000 (08:19 -0700)
committerGitHub <noreply@github.com>
Thu, 28 Apr 2022 15:19:07 +0000 (08:19 -0700)
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 4ed3900041c688a02dca1eb3323083d720dd0d93)

Co-authored-by: Abhigyan Bose <abhigyandeepbose@gmail.com>
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 c46bb302711fc5c9eca3c8c7b667f4d600fe3ae7..b9c22051f69d75a82c9fab1dd7a8a9fb7f9cd43f 100644 (file)
@@ -848,6 +848,7 @@ class Action(_AttributeHolder):
             'default',
             'type',
             'choices',
+            'required',
             'help',
             'metavar',
         ]
index dcc392faf231093684f6fa5d466da6acfde2936c..2d1cec13c22f3da0f24ca179aef59c149875290c 100644 (file)
@@ -4873,12 +4873,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):
@@ -4889,12 +4890,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.