-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Provide a better error for similar
methods with Dict
#17968
Conversation
d = Dict(:a=>"a") | ||
@test @inferred(map(identity, d)) == d | ||
@test @inferred(map(p->p.first=>p.second[1], d)) == Dict(:a=>'a') | ||
@test @inferred(map(p->p.second, d)) == Any["a"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I would be against sometimes mapping a Dict to a Dict, and sometimes to an array. Also I believe the collect
machinery assumes the container type doesn't depend on the element type --- as it runs, it might pick a new element type but keeps the container type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Should this be a deprecation or an outright error? In other words, would you be OK with moving the array-creating version to deprecated.jl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory it could be a deprecation, but the warning should not depend on
type inference, which might be more trouble than it's worth.
On Aug 11, 2016 2:28 PM, "Tim Holy" notifications@github.com wrote:
In test/dict.jl
#17968 (comment):@@ -388,6 +388,11 @@ d = Dict('a'=>1, 'b'=>1, 'c'=> 3)
@test [d[k] for k in keys(d)] == [d[k] for k in eachindex(d)] ==
[v for (k, v) in d] == [d[x[1]] for (i, x) in enumerate(d)]+# generators, similar
+d = Dict(:a=>"a")
+@test @inferred(map(identity, d)) == d
+@test @inferred(map(p->p.first=>p.second[1], d)) == Dict(:a=>'a')
+@test @inferred(map(p->p.second, d)) == Any["a"]Sounds good. Should this be a deprecation or an outright error? In other
words, would you be OK with moving the array-creating version to
deprecated.jl?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/JuliaLang/julia/pull/17968/files/3cfc74d47ddf7ffc9e9db32e3057ce648438fe1c#r74476669,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAtcbAYxqgPJaOFl02SP9tqPgBnZe1_Eks5qe2nPgaJpZM4JiQcr
.
Hmm, this is amusing: julia> d = Dict(:a=>"abc", :b=>"def")
Dict{Symbol,String} with 2 entries:
:a => "abc"
:b => "def"
julia> ret = [p for p in d]
2-element Array{Pair{Symbol,String},1}:
:a=>"abc"
:b=>"def"
julia> ret = [p->p[2] for p in d]
2-element Array{##4#6,1}:
#4
#4
julia> ret = [v for (k,v) in d]
2-element Array{String,1}:
"abc"
"def"
julia> ret = [v->v[1] for (k,v) in d]
2-element Array{##10#12,1}:
#10
#10 EDIT: this is on master, not this PR. |
…non-Pair return type
3cfc74d
to
eb95919
Compare
similar
methods for Dictsimilar
methods with Dict
Better? |
Yes, this is better. Whether you get the error depends on inference though, so it might be a bit jarring. |
Isn't that true of the current |
What's the status here, is this good to merge? |
Yes, we might as well do this. |
Fixes the following error:
Noticed from the PlotlyJS tests.