[issue42501] Improve error messages for argparse choices using enum

paul j3 report at bugs.python.org
Sun Nov 29 16:22:39 EST 2020


paul j3 <ajipanca at gmail.com> added the comment:

choices is fine for a few strings, but quickly becomes awkward with other types and large numbers.  The testing isn't an issue, since it just does a simple `in/contains` test.  But display, whether in usage, help or error, is problematic if you try anything too fancy.  metavar gets around some of those issues, but doesn't change the error messages.

Custom type or action is the best alternative.

I'm in favor omitting the enums mention in the docs, since it seems to be more confusing than helpful.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42501>
_______________________________________


More information about the Python-bugs-list mailing list