From 38e19d0abe03106c6ca0179cb9e3b70094e10725 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 4 Jul 2018 01:09:43 -0400 Subject: [PATCH] don't show module prefix in `:compact` printing mode --- base/arrayshow.jl | 11 ++++++----- base/show.jl | 9 ++++++++- test/core.jl | 2 +- test/enums.jl | 4 ++-- test/show.jl | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/base/arrayshow.jl b/base/arrayshow.jl index 0a50f47757a08..2a2ac29f7cb7f 100644 --- a/base/arrayshow.jl +++ b/base/arrayshow.jl @@ -312,7 +312,12 @@ print_array(io::IO, X::AbstractArray) = show_nd(io, X, print_matrix, true) # typeinfo aware # implements: show(io::IO, ::MIME"text/plain", X::AbstractArray) function show(io::IO, ::MIME"text/plain", X::AbstractArray) - # 0) compute new IOContext + # 0) show summary before setting :compact + summary(io, X) + isempty(X) && return + print(io, ":") + + # 1) compute new IOContext if !haskey(io, :compact) && _length(axes(X, 2)) > 1 io = IOContext(io, :compact => true) end @@ -321,10 +326,6 @@ function show(io::IO, ::MIME"text/plain", X::AbstractArray) io = IOContext(io, :limit => false) end - # 1) print summary info - summary(io, X) - isempty(X) && return - print(io, ":") if get(io, :limit, false) && displaysize(io)[1]-4 <= 0 return print(io, " …") else diff --git a/base/show.jl b/base/show.jl index bcc2bca0f0dcd..1b4b5b2fca7f8 100644 --- a/base/show.jl +++ b/base/show.jl @@ -369,7 +369,7 @@ function show(io::IO, f::Function) mt = ft.name.mt if isdefined(mt, :module) && isdefined(mt.module, mt.name) && getfield(mt.module, mt.name) === f - if is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main + if is_exported_from_stdlib(mt.name, mt.module) || mt.module === Main || get(io, :compact, false) print(io, mt.name) else print(io, mt.module, ".", mt.name) @@ -464,6 +464,13 @@ function show_type_name(io::IO, tn::Core.TypeName) end end sym = globfunc ? globname : tn.name + if get(io, :compact, false) + if globfunc + return print(io, "typeof(", sym, ")") + else + return print(io, sym) + end + end sym_str = string(sym) hidden = !globfunc && '#' ∈ sym_str quo = false diff --git a/test/core.jl b/test/core.jl index bc2abd188b666..0b194be42c9a0 100644 --- a/test/core.jl +++ b/test/core.jl @@ -1410,7 +1410,7 @@ struct Foo2509; foo::Int; end # issue #2517 struct Foo2517; end @test repr(Foo2517()) == "$(curmod_prefix)Foo2517()" -@test repr(Vector{Foo2517}(undef, 1)) == "$(curmod_prefix)Foo2517[$(curmod_prefix)Foo2517()]" +@test repr(Vector{Foo2517}(undef, 1)) == "$(curmod_prefix)Foo2517[Foo2517()]" @test Foo2517() === Foo2517() # issue #1474 diff --git a/test/enums.jl b/test/enums.jl index cd92216a5dd9b..9076f04a6c09f 100644 --- a/test/enums.jl +++ b/test/enums.jl @@ -135,11 +135,11 @@ end # test for unique Enum values @test_throws ArgumentError("values for Enum Test14 are not unique") @macrocall(@enum(Test14, _zero_Test14, _one_Test14, _two_Test14=0)) -@test repr(apple) == "apple::$(string(Fruit)) = 0" +@test repr(apple) == "apple::Fruit = 0" @test string(apple) == "apple" @test repr("text/plain", Fruit) == "Enum $(string(Fruit)):\napple = 0\norange = 1\nkiwi = 2" -@test repr("text/plain", orange) == "orange::$(curmod_prefix)Fruit = 1" +@test repr("text/plain", orange) == "orange::Fruit = 1" let io = IOBuffer() ioc = IOContext(io, :compact=>false) show(io, Fruit) diff --git a/test/show.jl b/test/show.jl index 395327a567f80..b097ec9bd0e2b 100644 --- a/test/show.jl +++ b/test/show.jl @@ -563,8 +563,8 @@ let @test sprint(show, B) == "\n [1, 1] = #undef\n [2, 2] = #undef\n [3, 3] = #undef" @test sprint(print, B) == "\n [1, 1] = #undef\n [2, 2] = #undef\n [3, 3] = #undef" B[1,2] = T12960() - @test sprint(show, B) == "\n [1, 1] = #undef\n [1, 2] = $(curmod_prefix)T12960()\n [2, 2] = #undef\n [3, 3] = #undef" - @test sprint(print, B) == "\n [1, 1] = #undef\n [1, 2] = $(curmod_prefix)T12960()\n [2, 2] = #undef\n [3, 3] = #undef" + @test sprint(show, B) == "\n [1, 1] = #undef\n [1, 2] = T12960()\n [2, 2] = #undef\n [3, 3] = #undef" + @test sprint(print, B) == "\n [1, 1] = #undef\n [1, 2] = T12960()\n [2, 2] = #undef\n [3, 3] = #undef" end # issue #13127