Open
Description
Bug report
Bug description:
It is impossible to combine the argparse
type
and choices
arguments in a meaningful way.
import argparse
parser = argparse.ArgumentParser()
days = ["mo", "tu", "we", "th", "fr", "sa", "su"]
def name_day(value):
return days.index(value) + 1
parser.add_argument(
'--days',
type=name_day,
choices=days,
)
args = [
"--days", "mo", "tu"
]
result = parser.parse_args(args)
This will result in the following error message:
example.py: error: argument --days: invalid choice: 1 (choose from 'mo', 'tu', 'we', 'th', 'fr', 'sa', 'su')
CPython versions tested on:
3.10, 3.13
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Projects
Status
No status