Skip to content
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

Use constructors in addition to convert to parse unknown types #95

Closed
mhauru opened this issue Feb 21, 2020 · 0 comments · Fixed by #96
Closed

Use constructors in addition to convert to parse unknown types #95

mhauru opened this issue Feb 21, 2020 · 0 comments · Fixed by #96

Comments

@mhauru
Copy link

mhauru commented Feb 21, 2020

I was recently trying to do something like this

@add_arg_table(settings
               , "--argname", arg_type=Symbol, default=:def
)

This fails, because the method convert(::Type{Symbol}, ::String) isn't defined. However, given that Symbol(::String) is defined, I think it would be sensible for ArgParse to use that. So I would propose something like replacing

parse_item(it_type::Type{T}, x::AbstractString) where {T} = convert(T, x)

with

parse_item(::Type{T}, x::AbstractString) where {T} = applicable(T, x) ? T(x) : convert(T, x)
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 a pull request may close this issue.

1 participant