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 avdwoude
Recipients avdwoude
Date 2020-10-29.07:45:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1603957526.8.0.0927596859344.issue42191@roundup.psfhosted.org>
In-reply-to
Content
When using a custom type in add_argument(), the error message on an incorrect value uses repr instead of str, which looks ugly.

Example code:

login2account = {
    c.account.login: c.account for c in self.admin.get_accounts()
}

action_add_parser.add_argument(
    "--user", 
    dest="user",
    type=lambda x: login2account.get(x, x),
    choices=list(login2account.values()), 
    help="Login name of the user",
)


When using an unknown user, the output is something alike:
   action add: error: argument --assignee: invalid choice: karen (choose from <Account(login=john)>, <Account(login=peter)>)

The culprit is the following line in lib.argparse._check_value():

    args = {'value': value,
            'choices': ', '.join(map(repr, action.choices))}

Which should be the following for prettier output:

    args = {'value': value,
            'choices': ', '.join(map(str, action.choices))}
History
Date User Action Args
2020-10-29 07:45:26avdwoudesetrecipients: + avdwoude
2020-10-29 07:45:26avdwoudesetmessageid: <1603957526.8.0.0927596859344.issue42191@roundup.psfhosted.org>
2020-10-29 07:45:26avdwoudelinkissue42191 messages
2020-10-29 07:45:26avdwoudecreate
Morty Proxy This is a proxified and sanitized view of the page, visit original site.