From 1bb49ac3fdb0f77cebd315998867bbe26c0ac8fd Mon Sep 17 00:00:00 2001 From: Abhigyan Bose Date: Thu, 28 Apr 2022 20:20:27 +0530 Subject: [PATCH] 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 4ed3900041c688a02dca1eb3323083d720dd0d93) Co-authored-by: Abhigyan Bose --- Lib/argparse.py | 1 + Lib/test/test_argparse.py | 6 ++++-- .../Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst | 1 + 3 files changed, 6 insertions(+), 2 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 2c0dd853a5bdd3..9be18488abe5ba 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -848,6 +848,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 d4426bab5e09a5..0b237ab5b93023 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -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): @@ -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): 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..0ebf7735465586 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-04-23-03-24-00.gh-issue-91832.TyLi65.rst @@ -0,0 +1 @@ +Add ``required`` attribute to :class:`argparse.Action` repr output. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy