From 8e7443732339a9ae1e0f4f1b9f9e726649b34fdc Mon Sep 17 00:00:00 2001 From: AbhigyanBose Date: Sat, 23 Apr 2022 03:54:18 +0530 Subject: [PATCH 1/4] Adding 'required' to names in Lib.argparse.Action --- Lib/argparse.py | 1 + Lib/test/test_argparse.py | 10 ++++++---- .../2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst diff --git a/Lib/argparse.py b/Lib/argparse.py index 429a72ab7841e7..668e1d416231fc 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -850,6 +850,7 @@ def _get_kwargs(self): 'default', 'type', 'choices', + 'required', 'help', 'metavar', ] diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 1f03b7fb24261b..4e013f7ade4a1f 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2265,7 +2265,7 @@ def test_help_blank(self): main description positional arguments: - foo + foo options: -h, --help show this help message and exit @@ -2282,7 +2282,7 @@ def test_help_blank(self): main description positional arguments: - {} + {} options: -h, --help show this help message and exit @@ -4902,12 +4902,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): @@ -4918,12 +4919,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): 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 index 00000000000000..b1e22a22439ae6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst @@ -0,0 +1 @@ +Added 'required' to names list in Lib.argparse.Action. From 144740105d0c28941be4616cd5a5892e93144d91 Mon Sep 17 00:00:00 2001 From: AbhigyanBose Date: Sat, 23 Apr 2022 04:24:30 +0530 Subject: [PATCH 2/4] Fixed accidental removal of trailing whitespaces. --- Lib/test/test_argparse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 4e013f7ade4a1f..db6cfed1a5b0fa 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -2265,7 +2265,7 @@ def test_help_blank(self): main description positional arguments: - foo + foo options: -h, --help show this help message and exit @@ -2282,7 +2282,7 @@ def test_help_blank(self): main description positional arguments: - {} + {} options: -h, --help show this help message and exit From 94d0853b0437755a11d47cddee1f32ae1c3cc5dd Mon Sep 17 00:00:00 2001 From: AbhigyanBose Date: Mon, 25 Apr 2022 21:33:50 +0530 Subject: [PATCH 3/4] Changed NEWS to better reflect code change. --- .../next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index b1e22a22439ae6..2f075ca569cfc8 100644 --- 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 @@ -1 +1 @@ -Added 'required' to names list in Lib.argparse.Action. +Add 'required' attr to argparse.Action repr. From cd0e30e508175dc137602b0d99e3725d4c58faf4 Mon Sep 17 00:00:00 2001 From: Abhigyan Bose Date: Thu, 28 Apr 2022 19:43:32 +0530 Subject: [PATCH 4/4] Update Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Éric --- .../next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 2f075ca569cfc8..0ebf7735465586 100644 --- 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 @@ -1 +1 @@ -Add 'required' attr to argparse.Action repr. +Add ``required`` attribute to :class:`argparse.Action` repr output.