Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Adding 'required' to names in Lib.argparse.Action
  • Loading branch information
AbhigyanBose committed Apr 25, 2022
commit 8e7443732339a9ae1e0f4f1b9f9e726649b34fdc
1 change: 1 addition & 0 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,7 @@ def _get_kwargs(self):
'default',
'type',
'choices',
'required',
'help',
'metavar',
]
Expand Down
10 changes: 6 additions & 4 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@ def test_help_blank(self):
main description

positional arguments:
foo
foo
Comment thread
merwok marked this conversation as resolved.
Outdated

options:
-h, --help show this help message and exit
Expand All @@ -2282,7 +2282,7 @@ def test_help_blank(self):
main description

positional arguments:
{}
{}
Comment thread
merwok marked this conversation as resolved.
Outdated

options:
-h, --help show this help message and exit
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added 'required' to names list in Lib.argparse.Action.
Copy link
Copy Markdown
Member

@merwok merwok Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python stdlib doesn’t use a root package name, Lib is just a source directory.

Suggested change
Added 'required' to names list in Lib.argparse.Action.
Added 'required' to names list in argparse.Action.

Also mentioning parameters may be clearer than names

Copy link
Copy Markdown
Contributor Author

@AbhigyanBose AbhigyanBose Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names is the name of the list in Action class that we are adding the element to. I should've put it in a code block.

How does this look ?
"Added an element required to the list names in argparse.Action._get_kwargs"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing. My point is that it does not matter that a line in the code uses names, it is not meaninfgul on its own when read by people in the NEWS.

Copy link
Copy Markdown
Contributor Author

@AbhigyanBose AbhigyanBose Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound then:

Added a parameter "required" to the list returned by _get_kwargs in argparse.Action.

Copy link
Copy Markdown
Member

@merwok merwok Apr 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug really is: required is missing from repr output
So this fix is doing: Add 'required' attr to argparse.Action repr
🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh..... Sorry, I'm still new here, and trying to get to know things. Thanks for taking the time to help me understand.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worry! There is info in the devguide: https://devguide.python.org/pullrequest/

(for future PRs, please don’t force push, it makes reviews harder)