Dict Types Behavior


#1

I was working with Dict recently and found some strange behavior, i dont know if its meant to be this way, but i got curious about the reasoning(if intended).

julia> Dict{Symbol,Union{Missing,Any}}()
Dict{Symbol,Any} with 0 entries

julia> dict = Dict{Symbol,Union{Missing,Any}}()
Dict{Symbol,Any} with 0 entries

julia> push!(dict,:a => missing, :b => "string")
Dict{Symbol,Any} with 2 entries:
  :a => missing
  :b => "string"

Here i pass explicitly the type of the dict, and Julia returns Dict{Symbol, Any}. As missing is a type too, converting to Any would be ok. But here is where i think its inconsistent:

julia> Dict(:a => missing, :b => "string")
Dict{Symbol,Union{Missing, String}} with 2 entries:
  :a => missing
  :b => "string"

In this case, passing directly on the constructor, it’s built with the desired type.


#2
julia> Union{Missing,Any}
Any

#3

Yes, it makes sense, but in the second example shouldnt the Dict have the type Any

, instead of Union{Missing,Any} too?


#4

It doesn’t have Union{Missing,Any} it has Union{Missing, String}.


#5

I see, thanks! Got it now.