Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee='https://github.com/merwok'closed_at=<Date2010-12-03.19:26:08.157>created_at=<Date2010-11-22.02:31:24.784>labels= ['type-bug', 'library']
title='Incorrect use of gettext in argparse'updated_at=<Date2010-12-03.19:26:08.156>user='https://github.com/merwok'
A bit of rationale behind the patch. You probably know that the gettext/_ functions serves two roles: Identifying the strings to translate, and retrieving the translation from a catalog.
At strings extraction time, the string in the line
msg = _('unknown parser %r (choices: %s)' % tup)
will be found by xgettext (just checked), so the .pot and .po files will include it. So far, so good.
At runtime however, the gettext function will get "unknown parser 'parserr' (choices: ('some', 'tuple'))" as argument, which isn’t in the translation catalogs. Doing the string interpolation after the gettext call (my patch) avoids this problem.
I’ve started on a test but I’m not sure how to proceed, since I need to use or intercept gettext and compare the error messages of argparse with translated messages to prove that the gettext calls are bogus. There are various ways of using or intercepting gettext from tests, but I have to experiment a bit before I can propose the simplest patch that could possibly work.
Exceptionally, I’d like to commit the change as is, and defer the testing for some months, until I can get to bpo-10529.
Yes, I think it's okay to fix this without a test, given that it's a nontrivial amount of work to test gettext stuff. I'd rather have it working now, without tests, than wait until we know how to test stuff with gettext.
It's also a pretty minor, obvious fix. Of course, I assume you'll make sure this also merges correctly with your bpo-10528 patch.
From the other bug: “If I understand it right, before this patch, people couldn't really supply internationalizations for these calls - they would have had to have a translation for each possible value of, e.g. action.choices or parser.prefix_chars.” Exactly.
I will commit this evening and refresh the other patch (there is one overlapping change).