Skip to content

gh-91832: Add 'required' attr to argparse.Action repr #91841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2022

Conversation

AbhigyanBose
Copy link
Contributor

@AbhigyanBose AbhigyanBose commented Apr 22, 2022

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

@fatihkabakk
Copy link
Contributor

fatihkabakk commented Apr 22, 2022

We got the same error, here is my pr #91840.
It's weird that when patchcheck made, it deletes whitespaces, but when not it throws error.
I also mentioned that problem on my comment in #91840 .

@AbhigyanBose
Copy link
Contributor Author

Thanks for pointing it out. I just realized the same.

@merwok merwok changed the title gh-91832: Adding 'required' to names in Lib.argparse.Action gh-91832: Adding 'required' to names in argparse.Action Apr 25, 2022
@@ -0,0 +1 @@
Added 'required' to names list in Lib.argparse.Action.
Copy link
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
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
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
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
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
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
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)

@merwok merwok changed the title gh-91832: Adding 'required' to names in argparse.Action gh-91832: Add 'required' attr to argparse.Action repr Apr 25, 2022
@terryjreedy
Copy link
Member

As suggested by Ronald Oussoren on core mentorship, changing a line like ' x ' to ' x \n' should solve the patchcheck failure.

In a future issue, parser.format_help might be modified to not format with trailing whitespace. I doubt that it is really needed.

Sidenote: I am not sure what you did, but force-pushing is rarely needed when revising PRs and sometimes messes them up.

@AbhigyanBose
Copy link
Contributor Author

@terryjreedy Got it. I just wasn't sure if I should change an unrelated test case's content in this particular PR. If that's what you and @merwok recommend I'll add in '\n' and then run make patchcheck before I submit.

I could also create a separate PR to add '\n' to that test case.

@terryjreedy
Copy link
Member

A separate PR would be OK. Azure Pipelines passing is not required but its failure from patchcheck failing is a nuisance.

@terryjreedy
Copy link
Member

I think Zachary Ware's suggestion of '\x20' might be even better. (How to fix argparse is not obvious. It uses %-formatting and I check all %s and no of format string I looked at had trailing spaces of format character that would produce such.)

@merwok
Copy link
Member

merwok commented Apr 25, 2022

This format spec does funky alignment:

action_header = '%*s%-*s ' % tup

@AbhigyanBose
Copy link
Contributor Author

AbhigyanBose commented Apr 27, 2022

@merwok and @terryjreedy

I created a new issue for this. I also proposed the solution I thought to be the simplest there.

@AbhigyanBose
Copy link
Contributor Author

#91984 has been resolved, thus make patchcheck is successful. Is there any other change required in this PR ?

Copy link
Member

@merwok merwok left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Minor change in news entry then this is good to go.
Can you check if backports to 3.10 and 3.9 are needed? (if the required attribute is present in these versions too)

@AbhigyanBose
Copy link
Contributor Author

Yeah. Seems like backports to 3.10 and 3.9 are necessary.(required is absent in both versions)

@merwok merwok added the needs backport to 3.9 only security fixes label Apr 28, 2022
@miss-islington
Copy link
Contributor

@AbhigyanBose: Status check is done, and it's a success ✅ .

@miss-islington miss-islington merged commit 4ed3900 into python:main Apr 28, 2022
@miss-islington
Copy link
Contributor

Thanks @AbhigyanBose for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9, 3.10.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-92021 is a backport of this pull request to the 3.10 branch.

@bedevere-bot
Copy link

GH-92022 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Apr 28, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 28, 2022
…-91841)

GH- Adding 'required' to names in Lib.argparse.Action

pythongh-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 4ed3900)

Co-authored-by: Abhigyan Bose <[email protected]>
miss-islington added a commit that referenced this pull request Apr 28, 2022
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 4ed3900)

Co-authored-by: Abhigyan Bose <[email protected]>
miss-islington added a commit that referenced this pull request Apr 28, 2022
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 4ed3900)

Co-authored-by: Abhigyan Bose <[email protected]>
hello-adam pushed a commit to hello-adam/cpython that referenced this pull request Jun 2, 2022
…-91841)

GH- Adding 'required' to names in Lib.argparse.Action

pythongh-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 4ed3900)

Co-authored-by: Abhigyan Bose <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants