-
Notifications
You must be signed in to change notification settings - Fork 39
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
Construction from generator may iterate a second time #86
Comments
So you use a generator expression to compute But all is fine if I adjust your code to use
Now the second iteration happens because of this method:
So if constructing the ordered dict throws an error, it tries to detect if the problem maybe was of a special kind, and if so produces a different error. Not sure why it does that; |
Oh I see -- this code changed over time. In Julia 1.6 till 1.10 we still have this the Julia stdlib: function Dict(kv)
try
dict_with_eltype((K, V) -> Dict{K, V}, kv, eltype(kv))
catch
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
throw(ArgumentError("Dict(kv): kv needs to be an iterator of tuples or pairs"))
else
rethrow()
end
end
end Only 1.11 changed this! In particular, your issue is triggered in exactly the same way with Julia <= 1.10:
As such I think there is nothing really here to do, we are just matching |
For example, this:
prints
(stack trace omitted)
The constructor shouldn't call my
expensive_function
again on previous elements.This seems also to affect some (all?) other structures in
DataStructures.jl
.The text was updated successfully, but these errors were encountered: