Skip to content

Commit

Permalink
fix argparse error
Browse files Browse the repository at this point in the history
  • Loading branch information
inisis committed Nov 26, 2024
1 parent 9a6efd3 commit 69b872f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions onnxslim/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,13 @@ def _add_arguments(self):
arg_type = _get_inner_type(field_def.type)
default_value = field_def.default if field_def.default is not field_def.default_factory else None
help_text = field_def.metadata.get("help", "")
nargs = "+" if arg_type == list else None
nargs = "+" if get_origin(arg_type) == list else None
choices = field_def.metadata.get("choices", None)

if choices and default_value is not None and default_value not in choices:
raise ValueError(
f"Invalid default value '{default_value}' for argument '{field_name}'. Must be one of {choices}."
)

arg_type = get_args(arg_type)[0] if get_args(arg_type) else arg_type
if arg_type == bool:
self.parser.add_argument(
f"--{field_name.replace('_', '-')}",
Expand Down

0 comments on commit 69b872f

Please sign in to comment.