Closed PleasantD closed 3 years ago
Thanks for posting @PleasantD!
Indeed, this seems related to #42, it appears like the parsing of Tuple
fields is bugged.
Additionally there should be parse error if the number of items for a fixed-length tuple does not match the definition. IE, specifying too few or too many values should generate an error if the tuple is of a fixed length.
The problem here seems to me more related to the Optional
annotation, as it's not easy to determine the right value to pass to the nargs
argument of add_argument
in this case.. Would you have an opinion on which value of 'nargs' would be appropriate in this case?
I'm fairly certain that the parsing of fixed length tuples (a.k.a fields annotated with Tuple[int, str, float]
etc.) works correctly, at least based on the following tests: https://github.com/lebrice/SimpleParsing/blob/master/test/test_tuples.py
Would you mind taking a quick glance at these tests, and letting me know what you think?
Thanks again for posting!
Just stumbled on the same issue. And yes it seems foo: Optional[Tuple[str, str]]
is broken, while foo:Tuple[str, str]
works fine. Same thing for Lists like foo: Optional[List[str]]
.
Shouldn't it be something like:
foo: Optional[Tuple[str, str]]
=> nargs=2
, required=Falsefoo: Tuple[str, str]
=> nargs=2
, required=Truefoo: Optional[List[str]]
=> nargs=*
, required=False, const=[]foo:List[str]
=> nargs=2
, required=TrueThis would even allow specifying (and differentiating) between []
and None
for optional lists, like:
None
--foo
=> []
--foo abc
=> ["abc"]
--foo abc def
=> ["abc", "def"]
Describe the bug Specifying a List or Tuple field as optional only accepts the first value.
To Reproduce
Expected behavior
args_values.cfg.values
should be the tuple(3,4)
andextra
should be[]
But insteadargs_values.cfg.values
is3
andextra
is['4']
Additionally there should be parse error if the number of items for a fixed-length tuple does not match the definition. IE, specifying too few or too many values should generate an error if the tuple is of a fixed length.