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

Dict(kw...) #25206

Closed
jw3126 opened this issue Dec 20, 2017 · 7 comments
Closed

Dict(kw...) #25206

jw3126 opened this issue Dec 20, 2017 · 7 comments

Comments

@jw3126
Copy link
Contributor

jw3126 commented Dec 20, 2017

A common pattern is converting keyword arguments into a Dict for easier manipulation. On master this currently throws an error:

julia> f(;kw...) = Dict(kw...)
f (generic function with 1 method)

julia> f(a=1)
ERROR: ArgumentError: Dict(kv): kv needs to be an iterator of tuples or pairs
Stacktrace:
 [1] Dict(::Int64) at ./dict.jl:147
 [2] #f#1 at ./REPL[1]:1 [inlined]
 [3] (::getfield(, Symbol("#kw##f")))(::NamedTuple{(:a,),Tuple{Int64}}, ::typeof(f)) at ./<missing>:0
 [4] top-level scope

I think a depwarn would be better. Especially for code that needs to work on v0.6 and master.

@fredrikekre
Copy link
Member

See #25179, you can use f(;kw...) = Dict(pairs(kw)) and f(;kw...) = Dict(Compat.pairs(kw)) on 0.6

@jw3126
Copy link
Contributor Author

jw3126 commented Dec 20, 2017

Thanks! Is there a reason other then lack of time for this having no depwarn?

@jw3126
Copy link
Contributor Author

jw3126 commented Dec 20, 2017

I am often in the situation that I have a package want to quickly try a feature on master. In this case I don't care if my package (or dependencies!) throw tons of depwarns, but an error is a problem. Thats why I would prefer a depwarn.

@JeffBezanson
Copy link
Member

kw will now support many dict operations, so it's possible a Dict is not needed anymore. Out of curiosity, what do you need the Dict for? (It doesn't negate the issue of course, just wondering about use cases.)

@JeffBezanson
Copy link
Member

Also duplicate of #25177

@jw3126
Copy link
Contributor Author

jw3126 commented Dec 20, 2017

I don't specifically need a Dict, just things like kw[:some_option]. And in v0.6 doing Dict(kw...) is a common trick to achieve this.

@JeffBezanson
Copy link
Member

kw[:some_option] should work now, as well as kw.some_option.

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

No branches or pull requests

3 participants