Message347742
Another workaround for who might ever need it. The benefit of this solution comparing to a custom type is that argparse will generate the help string properly with the choices, and this solution does workaround the place when the bug happens:
class Choices(tuple):
# Python bug https://bugs.python.org/issue27227
def __new__(cls, *args, **kwargs):
x = tuple.__new__(cls, *args, **kwargs)
Choices.__init__(x, *args, **kwargs)
return x
def __init__(self, *args, **kwargs):
self.default = []
def __contains__(self, item):
return tuple.__contains__(self, item) or item is self.default
choices = Choices(("value1", "value2", "value3", ...))
parser.add_argument(
...,
nargs="*",
choices=choices,
default=choices.default,
...) |
|
Date |
User |
Action |
Args |
2019-07-12 12:55:53 | João Eiras | set | recipients:
+ João Eiras, bethard, macfreek, eric.smith, eric.araujo, ced, deleted250130, thesociable, regis, berker.peksag, paul.j3, sebix |
2019-07-12 12:55:53 | João Eiras | set | messageid: <1562936153.17.0.511690868712.issue9625@roundup.psfhosted.org> |
2019-07-12 12:55:53 | João Eiras | link | issue9625 messages |
2019-07-12 12:55:52 | João Eiras | create | |
|