-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Description
Describe the bug
Optional positional arguments throw a "TypeError: 'required' is an invalid argument for positional" error in argparse.
To Reproduce
from dataclasses import dataclass
import simple_parsing
@dataclass
class Foo:
a: int | None = simple_parsing.field(positional=True, default=None)
simple_parsing.parse(Foo)Produces this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python3.12/site-packages/simple_parsing/parsing.py", line 1044, in parse
parsed_args = parser.parse_args(args)
^^^^^^^^^^^^^^^^^^^^^^^
File "/python3.12/argparse.py", line 1895, in parse_args
args, argv = self.parse_known_args(args, namespace)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/python3.12/site-packages/simple_parsing/parsing.py", line 345, in parse_known_args
self._preprocessing(args=args, namespace=namespace)
File "/python3.12/site-packages/simple_parsing/parsing.py", line 549, in _preprocessing
wrapped_dataclass.add_arguments(parser=self)
File "/python3.12/site-packages/simple_parsing/wrappers/dataclass_wrapper.py", line 214, in add_arguments
_ = group.add_argument(*wrapped_field.option_strings, **arg_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/python3.12/argparse.py", line 1459, in add_argument
kwargs = self._get_positional_kwargs(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/python3.12/argparse.py", line 1575, in _get_positional_kwargs
raise TypeError(msg)
TypeError: 'required' is an invalid argument for positional
Issue resolved in PR: #345
Metadata
Metadata
Assignees
Labels
No labels