Message399212
Dear all,
In the `argparse` module, the `ArgumentParser.add_subparsers()` method may call the `_()` translation function on user-provided strings. See e.g. Lib/argparse.py:1776 and Lib/argparse.py:L1777:
def add_subparsers(self, **kwargs):
# [...]
if 'title' in kwargs or 'description' in kwargs:
title = _(kwargs.pop('title', 'subcommands'))
description = _(kwargs.pop('description', None))
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 Lib/argparse.py:1704 then 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:
title = kwargs.pop('title', _('subcommands'))
description = kwargs.pop('description', None)
I'll submit a pull request with this change.
Kind regards,
Jérémie. |
|
Date |
User |
Action |
Args |
2021-08-08 08:42:38 | jdetrey | set | recipients:
+ jdetrey |
2021-08-08 08:42:38 | jdetrey | set | messageid: <1628412158.14.0.0114857952802.issue44864@roundup.psfhosted.org> |
2021-08-08 08:42:38 | jdetrey | link | issue44864 messages |
2021-08-08 08:42:37 | jdetrey | create | |
|