Skip to content

bpo-38821: Fix crash in argparse when using gettext #17192

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 4 commits into from
Nov 20, 2019

Conversation

federicobond
Copy link
Contributor

@federicobond federicobond commented Nov 16, 2019

gettext deprecated non-integer arguments for ngettext in bpo-28692
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@federicobond

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@brandtbucher
Copy link
Member

Thanks for your time, and welcome to CPython @federicobond!

I assume that you've seen the bot's message about the CLA?

@brandtbucher brandtbucher added the type-bug An unexpected behavior, bug, or error label Nov 16, 2019
@federicobond
Copy link
Contributor Author

Hi there @brandtbucher, yes. Waiting for the CLA to get accepted! Should I include a changelog in the PR?

@brandtbucher
Copy link
Member

Yes please! You can do so easily here.

@federicobond
Copy link
Contributor Author

Done! I was not feeling particularly inspired writing the news entry, so feel free to suggest changes.

@rhettinger
Copy link
Contributor

Please add a test.

@federicobond
Copy link
Contributor Author

I could not find any existing test exercising locale support in argparse. What would this test assert?

@taleinat
Copy link
Contributor

taleinat commented Nov 18, 2019

I could not find any existing test exercising locale support in argparse. What would this test assert?

I suggest testing various possible values for nargs, including all of the special ones, when using gettext.

@federicobond
Copy link
Contributor Author

I think adding those tests would be a great idea but none of them would fail prior to this change, so I am not sure we should bundle them together.

A proper regression test for this change needs to load a custom catalog, bind it to the global domain, etc.

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

Just a bit of clarification on the NEWS entry:

@taleinat
Copy link
Contributor

taleinat commented Nov 19, 2019

A proper regression test for this change needs to load a custom catalog, bind it to the global domain, etc.

We could also monkey-patch argparse._ and argparse.ngettext using unittest.mock.patch, which should be simpler to set up.

That being said, this PR is an obvious fix and we apparently have no existing tests for the use of gettext in argparse, so I realize that demanding that you add such tests is rather unfair. Let me know whether you'd like to try, and I'll take care of things even if you don't.

@federicobond
Copy link
Contributor Author

federicobond commented Nov 19, 2019

@taleinat sure, I can do that. Do you think those tests should accompany this PR or should I open a new one? I would rather submit another PR so we can discuss them separately and not stall this changeset, but whatever works best for the maintainers is good for me too.

@taleinat
Copy link
Contributor

@federicobond, yes, let's go with a separate issue and PR for adding such tests.

@taleinat taleinat merged commit be5c79e into python:master Nov 20, 2019
@miss-islington
Copy link
Contributor

Thanks @federicobond for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

I'm having trouble backporting to 3.8. Reason: 'Error 110 while writing to socket. Connection timed out.'. Please retry by removing and re-adding the needs backport to 3.8 label.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 20, 2019
@bedevere-bot
Copy link

GH-17288 is a backport of this pull request to the 3.7 branch.

@miss-islington
Copy link
Contributor

Thanks @federicobond for the PR, and @taleinat for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 20, 2019
@bedevere-bot
Copy link

GH-17289 is a backport of this pull request to the 3.8 branch.

@federicobond federicobond deleted the fix-issue-38821 branch November 20, 2019 13:47
miss-islington added a commit that referenced this pull request Nov 20, 2019
(cherry picked from commit be5c79e)

Co-authored-by: Federico Bond <[email protected]>
miss-islington added a commit that referenced this pull request Nov 20, 2019
(cherry picked from commit be5c79e)

Co-authored-by: Federico Bond <[email protected]>
@brandtbucher
Copy link
Member

Congrats on your first CPython contribution @federicobond! 🍾

Looking forward to seeing more from you in the future.

@federicobond
Copy link
Contributor Author

Thank you @brandtbucher & co! I can see that you have all put a lot of effort into making this a pleasurable experience, definitely makes me want to contribute again 🎉

jacobneiltaylor pushed a commit to jacobneiltaylor/cpython that referenced this pull request Dec 5, 2019
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants