-
Notifications
You must be signed in to change notification settings - Fork 11
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
Should Optional[Tuple[type1]]
be supported
#115
Comments
Seems like an oversight, and I would (probably?) accept a PR fixing it. It should also support |
Oh is this only for the optional tuple case? Or any optional container? And do you mind providing an example of the ambiguity that a 1-element tuple avoids? |
Say you have a parser for NoneType ( Your point about other optional containers makes me believe that I have indeed missed that problematic interaction previously; (PS: this discussion also applies to #116, of course.) |
Ahh got it, yeah I'll work on that when I get the chance |
So I was able to raise an error when an optional multiple item tuple with a custom none parser is provided, but I'm a bit confused on where to make the change such that the none parser is tried first in the list/one-item tuple case. For optional primitives, trying the none parser first is more straightforward because that can happen via the type set on the ArgumentParser argument. To do this with optional containers, would that need to happen in |
From a quick look, this is indeed not trivial to implement :-( and would probably require a bit of rearchitecting. Let's go for the simpler route of erroring out in all cases when a custom noneparser is present, we can always consider adding back support for the one-element case later. |
Sure, sounds good. I imagine wanting to have an optional tuple potentially parsed as None via the command line (rather than just using a default value of None) is a pretty rare use case anyway. |
I noticed that while
Optional[SomeContainer[type1]]
is supported for most of the containers defopt supports (i.e., List, Sequence, Collection, Iterable), it is not supported for Tuple. I would expectOptional[Tuple[type1]]
to behave similarly to other containers, in that it is treated as simplyTuple[type1]
. I was able to add support for this locally within a couple of minutes, but figured I would check to make sure it wasn't deliberately unsupported before pushing the fix.And thanks again for actively maintaining defopt! I use it quite a bit in my job.
The text was updated successfully, but these errors were encountered: