Skip to content

Commit 2cb04e0

Browse files
JeffBezansonStefanKarpinski
authored andcommitted
don't show module prefix in :compact printing mode (#27925)
1 parent bdfad24 commit 2cb04e0

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

base/arrayshow.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ print_array(io::IO, X::AbstractArray) = show_nd(io, X, print_matrix, true)
312312
# typeinfo aware
313313
# implements: show(io::IO, ::MIME"text/plain", X::AbstractArray)
314314
function show(io::IO, ::MIME"text/plain", X::AbstractArray)
315-
# 0) compute new IOContext
315+
# 0) show summary before setting :compact
316+
summary(io, X)
317+
isempty(X) && return
318+
print(io, ":")
319+
320+
# 1) compute new IOContext
316321
if !haskey(io, :compact) && length(axes(X, 2)) > 1
317322
io = IOContext(io, :compact => true)
318323
end
@@ -321,10 +326,6 @@ function show(io::IO, ::MIME"text/plain", X::AbstractArray)
321326
io = IOContext(io, :limit => false)
322327
end
323328

324-
# 1) print summary info
325-
summary(io, X)
326-
isempty(X) && return
327-
print(io, ":")
328329
if get(io, :limit, false) && displaysize(io)[1]-4 <= 0
329330
return print(io, "")
330331
else

base/show.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ function show(io::IO, f::Function)
369369
mt = ft.name.mt
370370
if isdefined(mt, :module) && isdefined(mt.module, mt.name) &&
371371
getfield(mt.module, mt.name) === f
372-
if is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main
372+
if is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main || get(io, :compact, false)
373373
print(io, mt.name)
374374
else
375375
print(io, mt.module, ".", mt.name)
@@ -464,6 +464,13 @@ function show_type_name(io::IO, tn::Core.TypeName)
464464
end
465465
end
466466
sym = globfunc ? globname : tn.name
467+
if get(io, :compact, false)
468+
if globfunc
469+
return print(io, "typeof(", sym, ")")
470+
else
471+
return print(io, sym)
472+
end
473+
end
467474
sym_str = string(sym)
468475
hidden = !globfunc && '#' sym_str
469476
quo = false

test/core.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ struct Foo2509; foo::Int; end
14101410
# issue #2517
14111411
struct Foo2517; end
14121412
@test repr(Foo2517()) == "$(curmod_prefix)Foo2517()"
1413-
@test repr(Vector{Foo2517}(undef, 1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]"
1413+
@test repr(Vector{Foo2517}(undef, 1)) == "$(curmod_prefix)Foo2517[Foo2517()]"
14141414
@test Foo2517() === Foo2517()
14151415

14161416
# issue #1474

test/enums.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ end
128128
# test for unique Enum values
129129
@test_throws ArgumentError("values for Enum Test14 are not unique") @macrocall(@enum(Test14, _zero_Test14, _one_Test14, _two_Test14=0))
130130

131-
@test repr(apple) == "apple::$(string(Fruit)) = 0"
131+
@test repr(apple) == "apple::Fruit = 0"
132132
@test string(apple) == "apple"
133133

134134
@test repr("text/plain", Fruit) == "Enum $(string(Fruit)):\napple = 0\norange = 1\nkiwi = 2"
135-
@test repr("text/plain", orange) == "orange::$(curmod_prefix)Fruit = 1"
135+
@test repr("text/plain", orange) == "orange::Fruit = 1"
136136
let io = IOBuffer()
137137
ioc = IOContext(io, :compact=>false)
138138
show(io, Fruit)

test/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ let
563563
@test sprint(show, B) == "\n [1, 1] = #undef\n [2, 2] = #undef\n [3, 3] = #undef"
564564
@test sprint(print, B) == "\n [1, 1] = #undef\n [2, 2] = #undef\n [3, 3] = #undef"
565565
B[1,2] = T12960()
566-
@test sprint(show, B) == "\n [1, 1] = #undef\n [1, 2] = $(curmod_prefix)T12960()\n [2, 2] = #undef\n [3, 3] = #undef"
567-
@test sprint(print, B) == "\n [1, 1] = #undef\n [1, 2] = $(curmod_prefix)T12960()\n [2, 2] = #undef\n [3, 3] = #undef"
566+
@test sprint(show, B) == "\n [1, 1] = #undef\n [1, 2] = T12960()\n [2, 2] = #undef\n [3, 3] = #undef"
567+
@test sprint(print, B) == "\n [1, 1] = #undef\n [1, 2] = T12960()\n [2, 2] = #undef\n [3, 3] = #undef"
568568
end
569569

570570
# issue #13127

0 commit comments

Comments
 (0)