Skip to content

Commit 6eec805

Browse files
authored
Merge pull request #24651 from JuliaLang/rf/typeinfo
IOContext: introduce the :typeinfo property
2 parents 1767963 + fe6709b commit 6eec805

File tree

12 files changed

+537
-428
lines changed

12 files changed

+537
-428
lines changed

base/arrayshow.jl

Lines changed: 487 additions & 0 deletions
Large diffs are not rendered by default.

base/grisu/grisu.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,21 @@ function Base.show(io::IO, x::Union{Float64,Float32})
118118
if get(io, :compact, false)
119119
_show(io, x, PRECISION, 6, x isa Float64, true)
120120
else
121-
_show(io, x, SHORTEST, 0, true, false)
121+
_show(io, x, SHORTEST, 0, get(io, :typeinfo, Any) !== typeof(x), false)
122122
end
123123
end
124124

125125
function Base.show(io::IO, x::Float16)
126-
if get(io, :compact, false)
126+
hastypeinfo = Float16 === get(io, :typeinfo, Any)
127+
# if hastypeinfo, the printing would be more compact using `SHORTEST`
128+
# while still retaining all the information
129+
# BUT: we want to print all digits in `show`, not in display, so we rely
130+
# on the :compact property to make the decision
131+
# (cf. https://github.com/JuliaLang/julia/pull/24651#issuecomment-345535687)
132+
if get(io, :compact, false) && !hastypeinfo
127133
_show(io, x, PRECISION, 5, false, true)
128134
else
129-
_show(io, x, SHORTEST, 0, true, false)
135+
_show(io, x, SHORTEST, 0, !hastypeinfo, false)
130136
end
131137
end
132138

base/precompile.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,6 @@ precompile(Tuple{typeof(Base.indexed_next), Tuple{Array{Int64, 1}, Void}, Int64,
15961596
precompile(Tuple{typeof(Base.setdiff), Array{Int64, 1}, Array{Int64, 1}})
15971597
precompile(Tuple{typeof(Base.Multimedia.display), Array{Int64, 1}})
15981598
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}, Int64})
1599-
precompile(Tuple{typeof(Base.array_eltype_show_how), Array{Int64, 1}})
16001599
precompile(Tuple{typeof(Base.summary), Array{Int64, 1}, Tuple{Base.OneTo{Int64}}})
16011600
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}, Int64, Int64})
16021601
precompile(Tuple{typeof(Base.isassigned), Array{Int64, 1}})
@@ -1608,9 +1607,8 @@ precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal},
16081607
precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal}, String, String})
16091608
precompile(Tuple{typeof(Base.print), Base.IOContext{Base.Terminals.TTYTerminal}, String, String, Char})
16101609
precompile(Tuple{typeof(Base.show_vector), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String, String})
1611-
precompile(Tuple{typeof(Base.print_matrix_repr), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
1612-
precompile(Tuple{typeof(Base.show_nd), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, typeof(Base.print_matrix_repr), Bool})
1613-
precompile(Tuple{typeof(Base.repremptyarray), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
1610+
precompile(Tuple{typeof(Base._show_nonempty), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String})
1611+
precompile(Tuple{typeof(Base._show_empty), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}})
16141612
precompile(Tuple{typeof(Base.print_matrix), Base.IOContext{Base.Terminals.TTYTerminal}, Array{Int64, 1}, String, String, String})
16151613
precompile(Tuple{typeof(Base.getindex), Base.ImmutableDict{Symbol, Any}, Symbol})
16161614
precompile(Tuple{typeof(Base.vcat), Base.OneTo{Int64}})

base/replutil.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function show(io::IO, ::MIME"text/plain", t::Task)
136136
end
137137
end
138138

139-
show(io::IO, ::MIME"text/plain", X::AbstractArray) = showarray(io, X, false)
139+
show(io::IO, ::MIME"text/plain", X::AbstractArray) = _display(io, X)
140140
show(io::IO, ::MIME"text/plain", r::AbstractRange) = show(io, r) # always use the compact form for printing ranges
141141

142142
# display something useful even for strings containing arbitrary
@@ -146,7 +146,7 @@ function show(io::IO, ::MIME"text/plain", s::String)
146146
show(io, s)
147147
else
148148
println(io, sizeof(s), "-byte String of invalid UTF-8 data:")
149-
showarray(io, Vector{UInt8}(s), false; header=false)
149+
print_array(io, Vector{UInt8}(s))
150150
end
151151
end
152152

base/set.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,9 @@ similar(s::Set{T}) where {T} = Set{T}()
2929
similar(s::Set, T::Type) = Set{T}()
3030

3131
function show(io::IO, s::Set)
32-
print(io, "Set")
33-
if isempty(s)
34-
print(io, "{", eltype(s), "}()")
35-
return
36-
end
37-
print(io, "(")
38-
show_vector(io, s, "[", "]")
39-
print(io, ")")
32+
print(io, "Set(")
33+
show_vector(io, s)
34+
print(io, ')')
4035
end
4136

4237
isempty(s::Set) = isempty(s.dict)

0 commit comments

Comments
 (0)