Closed yycho0108 closed 3 years ago
Thanks a lot @yycho0108 , this is really neat! I'll create a new release (v0.0.15.post2
) to include your changes!
Would you mind rebasing your branch on master
before I merge this?
Yep, rebased just now. Thanks!
Hi again! This is Yoonyoung (Jamie) Cho.
I've been using
SimpleParsing
quite a lot recently, and I've come across a use case for serialization for variable-length homogeneous tuples. There was aTODO
(# TODO: support the Ellipsis?
) and I needed this capability, so I figured I should create a PR for this feature. Hopefully this is useful.Description
Currently,
decode_tuple()
cannot handle cases such asTuple[int,...]
. There's a check inparse_tuple()
that deals with ellipses, but similar fix was not adopted for serialization (decoding such tuples) - I tried to follow the same style as the existing function, which looks to be more robust than simply checking fortuple_item_types[0]
, although I agree with the comments that in general the only allowable form of such tuples isTuple[T, ...]
(other uses of ellipses would result in aTypeError
such asTuple[t0, t1, ...]: each t must be a type. Got Ellipsis.
).I also added a test in
utils/test_serialization.py
for simply checking the equivalence of the dataclass instance after saving to and loading from the serialized string.Pytest
Hopefully this is useful!