Skip to content

Commit 3c2a6e8

Browse files
authored
show: differentiate TypeName and wrapper when printing (#36303)
1 parent d19a279 commit 3c2a6e8

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

base/abstractdict.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct ValueIterator{T<:AbstractDict}
4545
end
4646

4747
function summary(io::IO, iter::T) where {T<:Union{KeySet,ValueIterator}}
48-
print(io, T.name, " for a ")
48+
print(io, T.name.name, " for a ")
4949
summary(io, iter.dict)
5050
end
5151

@@ -558,7 +558,7 @@ Dict{Symbol,Int64} with 2 entries:
558558
:b => 2
559559
560560
julia> map!(v -> v-1, values(d))
561-
Base.ValueIterator for a Dict{Symbol,Int64} with 2 entries. Values:
561+
ValueIterator for a Dict{Symbol,Int64} with 2 entries. Values:
562562
0
563563
1
564564
```

base/arrayshow.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,9 @@ function typeinfo_prefix(io::IO, X)
516516

517517
if X isa AbstractDict
518518
if eltype_X == eltype_ctx
519-
string(typeof(X).name), false
519+
sprint(show_type_name, typeof(X).name), false
520520
elseif !isempty(X) && typeinfo_implicit(keytype(X)) && typeinfo_implicit(valtype(X))
521-
string(typeof(X).name), true
521+
sprint(show_type_name, typeof(X).name), true
522522
else
523523
string(typeof(X)), false
524524
end
@@ -529,7 +529,7 @@ function typeinfo_prefix(io::IO, X)
529529
elseif !isempty(X) && typeinfo_implicit(eltype_X)
530530
"", true
531531
elseif print_without_params(eltype_X)
532-
string(unwrap_unionall(eltype_X).name), false # Print "Array" rather than "Array{T,N}"
532+
sprint(show_type_name, unwrap_unionall(eltype_X).name), false # Print "Array" rather than "Array{T,N}"
533533
else
534534
string(eltype_X), false
535535
end

base/essentials.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ of a general iterator are normally considered its "values".
750750
julia> d = Dict("a"=>1, "b"=>2);
751751
752752
julia> values(d)
753-
Base.ValueIterator for a Dict{String,Int64} with 2 entries. Values:
753+
ValueIterator for a Dict{String,Int64} with 2 entries. Values:
754754
2
755755
1
756756

base/show.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ function show(io::IO, @nospecialize(x::Type))
499499
show_datatype(io, x)
500500
return
501501
elseif x isa Union
502-
if x.a isa DataType && Core.Compiler.typename(x.a) === Core.Compiler.typename(DenseArray)
502+
if x.a isa DataType && x.a.name === typename(DenseArray)
503503
T, N = x.a.parameters
504504
if x == StridedArray{T,N}
505505
print(io, "StridedArray")
@@ -522,7 +522,7 @@ function show(io::IO, @nospecialize(x::Type))
522522
x::UnionAll
523523

524524
if print_without_params(x)
525-
return show(io, unwrap_unionall(x).name)
525+
return show_type_name(io, unwrap_unionall(x).name)
526526
end
527527

528528
if x.var.name === :_ || io_has_tvar_name(io, x.var.name, x)
@@ -593,6 +593,7 @@ function show_type_name(io::IO, tn::Core.TypeName)
593593
show_sym(io, sym)
594594
quo && print(io, ")")
595595
globfunc && print(io, ")")
596+
nothing
596597
end
597598

598599
function show_datatype(io::IO, x::DataType)
@@ -647,7 +648,9 @@ macro show(exs...)
647648
end
648649

649650
function show(io::IO, tn::Core.TypeName)
651+
print(io, "typename(")
650652
show_type_name(io, tn)
653+
print(io, ")")
651654
end
652655

653656
show(io::IO, ::Nothing) = print(io, "nothing")

src/rtutils.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,11 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt
813813
n += jl_printf(out, " where ");
814814
n += jl_static_show_x(out, (jl_value_t*)ua->var, depth->prev);
815815
}
816+
else if (vt == jl_typename_type) {
817+
n += jl_printf(out, "typename(");
818+
n += jl_static_show_x(out, jl_unwrap_unionall(((jl_typename_t*)v)->wrapper), depth);
819+
n += jl_printf(out, ")");
820+
}
816821
else if (vt == jl_tvar_type) {
817822
// show type-var bounds only if they aren't going to be printed by UnionAll later
818823
jl_tvar_t *var = (jl_tvar_t*)v;

test/dict.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,35 +1062,35 @@ end
10621062
@test String(take!(buf)) == "Base.ImmutableDict{$Int,$Int} with 1 entry: …"
10631063
show(io, MIME"text/plain"(), keys(d))
10641064
@test String(take!(buf)) ==
1065-
"Base.KeySet for a Base.ImmutableDict{$Int,$Int} with 1 entry. Keys: …"
1065+
"KeySet for a Base.ImmutableDict{$Int,$Int} with 1 entry. Keys: …"
10661066

10671067
io = IOContext(io, :displaysize => (5, 80))
10681068
show(io, MIME"text/plain"(), d)
10691069
@test String(take!(buf)) == "Base.ImmutableDict{$Int,$Int} with 1 entry:\n 1 => 2"
10701070
show(io, MIME"text/plain"(), keys(d))
10711071
@test String(take!(buf)) ==
1072-
"Base.KeySet for a Base.ImmutableDict{$Int,$Int} with 1 entry. Keys:\n 1"
1072+
"KeySet for a Base.ImmutableDict{$Int,$Int} with 1 entry. Keys:\n 1"
10731073
d = Base.ImmutableDict(d, 3=>4)
10741074
show(io, MIME"text/plain"(), d)
10751075
@test String(take!(buf)) == "Base.ImmutableDict{$Int,$Int} with 2 entries:\n ⋮ => ⋮"
10761076
show(io, MIME"text/plain"(), keys(d))
10771077
@test String(take!(buf)) ==
1078-
"Base.KeySet for a Base.ImmutableDict{$Int,$Int} with 2 entries. Keys:\n"
1078+
"KeySet for a Base.ImmutableDict{$Int,$Int} with 2 entries. Keys:\n"
10791079

10801080
io = IOContext(io, :displaysize => (6, 80))
10811081
show(io, MIME"text/plain"(), d)
10821082
@test String(take!(buf)) ==
10831083
"Base.ImmutableDict{$Int,$Int} with 2 entries:\n 3 => 4\n 1 => 2"
10841084
show(io, MIME"text/plain"(), keys(d))
10851085
@test String(take!(buf)) ==
1086-
"Base.KeySet for a Base.ImmutableDict{$Int,$Int} with 2 entries. Keys:\n 3\n 1"
1086+
"KeySet for a Base.ImmutableDict{$Int,$Int} with 2 entries. Keys:\n 3\n 1"
10871087
d = Base.ImmutableDict(d, 5=>6)
10881088
show(io, MIME"text/plain"(), d)
10891089
@test String(take!(buf)) ==
10901090
"Base.ImmutableDict{$Int,$Int} with 3 entries:\n 5 => 6\n ⋮ => ⋮"
10911091
show(io, MIME"text/plain"(), keys(d))
10921092
@test String(take!(buf)) ==
1093-
"Base.KeySet for a Base.ImmutableDict{$Int,$Int} with 3 entries. Keys:\n 5\n"
1093+
"KeySet for a Base.ImmutableDict{$Int,$Int} with 3 entries. Keys:\n 5\n"
10941094
end
10951095

10961096
@testset "copy!" begin

test/show.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ end
616616
@test_repr "Array{<:Real}"
617617
@test_repr "Array{>:Real}"
618618

619+
@test repr(Base.typename(Array)) == "typename(Array)"
620+
619621
let oldout = stdout, olderr = stderr
620622
local rdout, wrout, rderr, wrerr, out, err, rd, wr, io
621623
try

0 commit comments

Comments
 (0)