You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[argparse] Do not translate user-provided strings in ArgumentParser.add_subparsers() #89027
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
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-08-08.08:42:38.108>labels= ['type-feature', 'library', '3.11']
title='[argparse] Do not translate user-provided strings in `ArgumentParser.add_subparsers()`'updated_at=<Date2021-08-25.09:24:41.860>user='https://github.com/jdetrey'
In the argparse module, the ArgumentParser.add_subparsers() method may call the _() translation function on user-provided strings. See e.g. 3.9/Lib/argparse.py:1776 and 3.9/Lib/argparse.py:L1777:
When elements 'title' and/or 'description' are set in kwargs, they will be popped from the dictionary and then fed to _(). However, these are user-provided strings, and it seems to me that translating them should be the user's responsibility. This seems to be the expected behavior for all other user-provided strings in the argparse module: see e.g. the ArgumentParser's description parameter (in 3.9/Lib/argparse.py:1704 then 3.9/Lib/argparse.py:1312), which never gets translated by the argparse module.
However, the default title string 'subcommands' should still be localized. Therefore, I'd suggest restricting the call to _() to this string only, as in the following:
Activity
jdetrey commentedon Aug 8, 2021
Dear all,
In the
argparsemodule, theArgumentParser.add_subparsers()method may call the_()translation function on user-provided strings. See e.g. 3.9/Lib/argparse.py:1776 and 3.9/Lib/argparse.py:L1777:When elements
'title'and/or'description'are set inkwargs, they will be popped from the dictionary and then fed to_(). However, these are user-provided strings, and it seems to me that translating them should be the user's responsibility. This seems to be the expected behavior for all other user-provided strings in theargparsemodule: see e.g. theArgumentParser'sdescriptionparameter (in 3.9/Lib/argparse.py:1704 then 3.9/Lib/argparse.py:1312), which never gets translated by theargparsemodule.However, the default title string
'subcommands'should still be localized. Therefore, I'd suggest restricting the call to_()to this string only, as in the following:I'll submit a pull request with this change.
Kind regards,
Jérémie.
15 remaining items
serhiy-storchaka commentedon Sep 25, 2024
This is a bug (
Tools/i18n/pygettext.pyeven emits warnings for this) and the fix should be backported.