Open
Description
Bug report
Bug description:
Combining argparse
type
and choices
arguments results in cryptic usage messages.
import argparse
parser = argparse.ArgumentParser()
day_names = ["mo", "tu", "we", "th", "fr", "sa", "su"]
days = [1, 2, 3, 4, 5, 6, 7]
def name_day(value):
return day_names.index(value) + 1
parser.add_argument(
'--day',
type=name_day,
choices=days,
)
parser.parse_args()
This will result in the following usage message:
usage: example.py [-h] [--day {1,2,3,4,5,6,7}]
This is strange, because the user is expected to enter the day name as a string.
See https://discuss.python.org/t/argparse-unable-to-combine-type-and-choices/88687 for discussion.
CPython versions tested on:
3.10, 3.13
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Projects
Status
No status