This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jdetrey
Recipients jdetrey
Date 2021-08-08.08:42:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628412158.14.0.0114857952802.issue44864@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-08-08 08:42:38jdetreysetrecipients: + jdetrey
2021-08-08 08:42:38jdetreysetmessageid: <1628412158.14.0.0114857952802.issue44864@roundup.psfhosted.org>
2021-08-08 08:42:38jdetreylinkissue44864 messages
2021-08-08 08:42:37jdetreycreate