Skip to content

Fix check_default_type_multi and check_default_type_multi2 #5

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

Conversation

kshramt
Copy link

@kshramt kshramt commented Feb 1, 2014

No description provided.

@carlobaldassi
Copy link
Owner

I'm looking into that, but I suspect that in check_default_type_multi it is the error message which is wrong. I'm almost sure check_default_type_multi2 is correct. Can you provide a use case of what you have tried?

@kshramt
Copy link
Author

kshramt commented Feb 4, 2014

  1. arg_type <: eltype(default) in check_default_type_multi is inconsistent with typeof(default) <: arg_type in check_default_type.
  2. An use case is:
using ArgParse

settings = ArgParseSettings()
@add_arg_table(settings, "arg", action=>:store_arg, nargs=>2, default=>["p", "q"]) # error

carlobaldassi added a commit that referenced this pull request Feb 4, 2014
Different behaviour for multi-nargs and multi-actions
(multi-nargs is more permissive).

Also minor fixes.

Still addressing #5.
@carlobaldassi
Copy link
Owner

Ok, I pushed a change which makes the use case work. Thanks for reporting. The thing which still makes me a little uncomfortable is that now you can have a default such as ["p", "q"] which is a Vector{ASCIIString}, but if you pass p and q as arguments to your program you'll get {"p", "q"}, i.e. a Vector{Any}. I was thinking of issuing a warning in these situations, but maybe that'd be nagging. Comments welcome.

About the difference between check_default_type and check_default_type_multi: it's not inconsistent, and the reason is that there's a difference between the eltype of a Vector and the type of each of its elements. The previous version was checking that arg_type <: eltype(default) as a way to ensure that pushing something of type arg_type to the vector was allowed; this was indended for the multi-action case (e.g. action = :append_arg) and I therefore relaxed it for the multi-nargs case; notice that in both cases it is still checked that isa(x, arg_type) holds for each element x of the vector, which corresponds to the test in check_default_type.
(Same argument for check_default_type_multi2.)

@kshramt
Copy link
Author

kshramt commented Feb 5, 2014

The thing which still makes me a little uncomfortable is that now you can have a default such as ["p", "q"] which is a Vector{ASCIIString}, but if you pass p and q as arguments to your program you'll get {"p", "q"}, i.e. a Vector{Any}.

I am not sure if this behavior causes any problems.

The previous version was checking that arg_type <: eltype(default) as a way to ensure that pushing something of type arg_type to the vector was allowed; this was indended for the multi-action case (e.g. action = :append_arg) and I therefore relaxed it for the multi-nargs case

I understand. Thank you for your explanations and modifications!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants