Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create show_supertypes function #21443

Merged
merged 2 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ function summarize(io::IO, T::DataType, binding)
end
println(io, "```")
end
if supertype(T) != Any
println(io, "**Supertype Hierarchy:**")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should these both be capitalized?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using title case for headings

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 @@ -750,6 +750,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 @@ -760,6 +765,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 @@ -777,6 +787,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 @@ -670,3 +670,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"