-
-
Notifications
You must be signed in to change notification settings - Fork 63
The choices parameter of add_argument() is not functioning correctly. #427
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
🐛 Bug report
To reproduce
from jsonargparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("--mode", type=int, default=1, choices=[0, 1])
cfg = parser.parse_args()
print(cfg.mode)Output:
> python argparse_test.py --mode 1
usage: argparse_test.py [-h] [--mode {0,1}]
argparse_test.py: error: argument --mode: invalid choice: '1' (choose from 0, 1)Expected behavior
Aligned with argparse.
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--mode", type=int, default=1, choices=[0, 1])
cfg = parser.parse_args()
print(cfg.mode)Output:
> python argparse_test.py --mode 1
1Environment
- jsonargparse version (e.g., 4.8.0): 4.27.1
- Python version (e.g., 3.9): 3.8.17
- How jsonargparse was installed (e.g.
pip install jsonargparse[all]): pip install jsonargparse[signatures,omegaconf,urls]>=4.25.0 - OS (e.g., Linux): Ubuntu 20.04.5 LTS
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working