-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can I use Ellipses in types? #40
Comments
When I was implementing the type hint support I decided to leave ellipses for a future improvement since it wasn't required for me at that moment. From what I see I forgot to mention this in the documentation. But certainly this can be added. |
Pretty incredible amount that you did incorporate. Ellipses aren't a huge deal as far as I am concerned, but I am a bit puzzled re: why nesting tuples like this doesn't work for me. Any thoughts? Tuple[Tuple[str, str], Tuple[Tuple[int, float], Tuple[int, float]]] I get the ValueError: not enough values to unpack (expected 3, got 2) -- shown above. |
I think I have never tried tuples inside tuples so very likely this can be a bug. Need to look at it in more detail. |
Indeed nested tuples is not working correctly. And not just because of the error you are getting. For instance |
- Fixed nested tuples were not working correctly #40. - Added unit test for dict type. - Preparing for release 3.5.0.
Both the support for ellipsis and the correct handling of nested tuples is fixed in the latest release v3.5.0. Please check. |
So far so good -- testing nested tuples and with ellipsis. Thanks much! |
Parameterizations are often expressed as a tuple of keys followed by a sequence of tuples of values in order to express a sequence of mapping of the keys to the values, eg I might write (('foo', 'bar'), ((1, 0.3), (5, 0.9)) to mean ({'foo': 1, 'bar': 0.3}, {'foo': 5, 'bar': 0.9}). I'm trying to do this using jsonargparse, but I am fairly ignorant with python's typing module and argument parsing in general.
This appears to be a valid type: Tuple[Tuple[str, str], Tuple[Tuple[int, float],...]] , as the Ellipsis operate on a 'single' type Tuple[int, float] in the Tuple. However, when I try the code (below) with either Ellipsis (commented out), or repeating two Tuple[int, float] elements, I get the same error (ValueError: not enough values to unpack (expected 3, got 2)). If I only have one nested level it works ok, eg Tuple[Tuple[str, str], Tuple[int, float], Tuple[int, float]] which is often ok, but as I understand it I can't use Ellipsis on a Tuple with elements of more than one type, and this flattened parameterization has two types, the keys and the values.
I really appreciate jsonargparse's ability to map dataclasses to argparser -- that's the functionality I need. I might well be overlooking something regarding argparse or python's typing module, or some of the other dependencies.
The text was updated successfully, but these errors were encountered: