Skip to content

Commit a330d54

Browse files
authored
treat empty AbstractVector like empty Vector in print_array (#57898)
I don't see why an empty `Vector` should be displayed differently from any other empty `AbstractVector`. Here is an example using views: `Vector` (both master and this PR): ``` julia> [collect(Int8, 1:k) for k in (0,2)] 2-element Vector{Vector{Int8}}: [] [1, 2] julia> Any[collect(Int8, 1:k) for k in (0,2)] 2-element Vector{Any}: Int8[] Int8[1, 2] ``` `AbstractVector` in master: ``` julia> v = Int8[1,2]; [view(v, 1:k) for k in (0,2)] 2-element Vector{SubArray{Int8, 1, Vector{Int8}, Tuple{UnitRange{Int64}}, true}}: 0-element view(::Vector{Int8}, 1:0) with eltype Int8 [1, 2] julia> v = Int8[1,2]; Any[view(v, 1:k) for k in (0,2)] 2-element Vector{Any}: 0-element view(::Vector{Int8}, 1:0) with eltype Int8 Int8[1, 2] ``` `AbstractVector` with this PR: ``` julia> v = Int8[1,2]; [view(v, 1:k) for k in (0,2)] 2-element Vector{SubArray{Int8, 1, Vector{Int8}, Tuple{UnitRange{Int64}}, true}}: [] [1, 2] julia> v = Int8[1,2]; Any[view(v, 1:k) for k in (0,2)] 2-element Vector{Any}: Int8[] Int8[1, 2] ```
1 parent 2dc5928 commit a330d54

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

base/arrayshow.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ print_array(io::IO, X::AbstractArray) = show_nd(io, X, print_matrix, true)
361361
# typeinfo aware
362362
# implements: show(io::IO, ::MIME"text/plain", X::AbstractArray)
363363
function show(io::IO, ::MIME"text/plain", X::AbstractArray)
364-
if isempty(X) && (get(io, :compact, false)::Bool || X isa Vector)
364+
if isempty(X) && (get(io, :compact, false)::Bool || X isa AbstractVector)
365365
return show(io, X)
366366
end
367367
# 1) show summary before setting :compact

0 commit comments

Comments
 (0)