Skip to content

Commit

Permalink
Merge pull request #21443 from JuliaLang/cv/show_supertypes
Browse files Browse the repository at this point in the history
Create show_supertypes function
  • Loading branch information
omus authored May 17, 2017
2 parents cff2d75 + 2478f29 commit c2992ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,13 @@ function summarize(io::IO, T::DataType, binding)
end
println(io, "```")
end
if supertype(T) != Any
println(io, "**Supertype Hierarchy:**")
println(io, "```")
Base.show_supertypes(io, T)
println(io)
println(io, "```")
end
end

function summarize(io::IO, m::Module, binding)
Expand Down
10 changes: 10 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ function show_datatype(io::IO, x::DataType)
end
end

function show_supertypes(io::IO, typ::DataType)
print(io, typ)
while typ != Any
typ = supertype(typ)
print(io, " <: ", typ)
end
end

show_supertypes(typ::DataType) = show_supertypes(STDOUT, typ)

macro show(exs...)
blk = Expr(:block)
for ex in exs
Expand Down
15 changes: 15 additions & 0 deletions test/docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ abstract type $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A
```
$(curmod_prefix)Undocumented.D
```
**Supertype Hierarchy:**
```
$(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.B), doc"$doc_str")

Expand All @@ -759,6 +764,11 @@ No documentation found.
```
mutable struct $(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A
```
**Supertype Hierarchy:**
```
$(curmod_prefix)Undocumented.C <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.C), doc"$doc_str")

Expand All @@ -776,6 +786,11 @@ one :: Any
two :: String
three :: Float64
```
**Supertype Hierarchy:**
```
$(curmod_prefix)Undocumented.D <: $(curmod_prefix)Undocumented.B <: $(curmod_prefix)Undocumented.A <: Any
```
""")
@test docstrings_equal(@doc(Undocumented.D), doc"$doc_str")

Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,6 @@ let m = which(T20332{Int}(), (Int,)),
end

@test sprint(show, Main) == "Main"

@test sprint(Base.show_supertypes, Int64) == "Int64 <: Signed <: Integer <: Real <: Number <: Any"
@test sprint(Base.show_supertypes, Vector{String}) == "Array{String,1} <: DenseArray{String,1} <: AbstractArray{String,1} <: Any"

0 comments on commit c2992ac

Please sign in to comment.