Skip to content

0/1 printing of false/true is confusing in Dict #30683

@tkf

Description

@tkf
julia> VERSION
v"1.2.0-DEV.146"

julia> show(Dict(true => false))
Dict(1=>0)

Also,

julia> Dict(true => false)
Dict{Bool,Bool} with 1 entry:
  true => false

seems to be inconsistent with

julia> [true => false]
1-element Array{Pair{Bool,Bool},1}:
 1 => 0

It looks like display(Dict(...)) does not set typeinfo while show(Dict(...)) does. Here is the code I used to check it:

function logio_show(io, mime)
    push!(logio_log, ("mime", mime))
    push!(logio_log, ("io isa IOContext", io isa IOContext))
    if io isa IOContext
        push!(logio_log, ("io.dict", io.dict))
    end
    print(io, "LogIO")
end

Base.show(io::IO, mime::MIME"text/plain", ::LogIO) =
    logio_show(io, mime)

Base.show(io::IO, ::LogIO) =
    logio_show(io, nothing)

then

empty!(logio_log)
display(Dict(:a=>LogIO()))
logio_log

shows

3-element Array{Any,1}:
 ("mime", nothing)                                                                                                
 ("io isa IOContext", true)                                                                                       
 ("io.dict", Base.ImmutableDict{Symbol,Any}(:compact=>true,:SHOWN_SET=>Dict(:a=>LogIO),:module=>Main,:limit=>true,:color=>true))

(i.e., no typeinfo) while

empty!(logio_log)
show(Dict(:a=>LogIO()))
logio_log

shows

3-element Array{Any,1}:
 ("mime", nothing)                                                                                                
 ("io isa IOContext", true)                                                                                       
 ("io.dict", Base.ImmutableDict{Symbol,Any}(:typeinfo=>LogIO,:compact=>true,:compact=>true,:typeinfo=>Pair{Symbol,LogIO},:SHOWN_SET=>Dict(:a=>LogIO),:color=>true))

i.e., typeinfo is set to LogIO.

Metadata

Metadata

Assignees

No one assigned

    Labels

    display and printingAesthetics and correctness of printed representations of objects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions