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

Create show_supertypes function #21443

merged 2 commits into from
May 17, 2017

Conversation

omus
Copy link
Member

@omus omus commented Apr 19, 2017

A colleague of mine wanted to visualize the type hierarchy so I came up with this. I would like to potentially work it into show itself but I was unsure how I should integrate this.

@StefanKarpinski
Copy link
Member

Maybe part of the ?T output for a type?

@ararslan ararslan added display and printing Aesthetics and correctness of printed representations of objects. types and dispatch Types, subtyping and method dispatch labels Apr 19, 2017
@omus
Copy link
Member Author

omus commented Apr 22, 2017

Added show_supertypes into type help:

help?> Integer
search: Integer isinteger

  No documentation found.

  Summary:

  abstract type Integer <: Real

  Subtypes:

  BigInt
  Bool
  Signed
  Unsigned

  Supertype Hierarchy:

  Integer <: Real <: Number <: Any

@omus
Copy link
Member Author

omus commented Apr 22, 2017

Additionally, limited the number of displayed subtypes in the type help:

help?> Any
search: Any any ANY any! listenany randcycle code_warntype ReadOnlyMemoryError @code_warntype isreadonly

  No documentation found.

  Summary:

  abstract type Any <: Any

  Subtypes:

  AbstractArray
  AbstractChannel
  AbstractRNG
  AbstractSerializer
  AbstractSet
  AbstractString
  Any
  Associative
  Base.AbstractCartesianIndex
  Base.AbstractCmd
  Base.AsyncCollector
  Base.AsyncCollectorState
  Base.AsyncCondition
  Base.AsyncGenerator
  Base.AsyncGeneratorState
  Base.BaseDocs.Keyword
  Base.Cartesian.LReplace
  Base.ChannelIterState
  Base.CodegenHooks
  Base.CodegenParams
  ...

julia> length(subtypes(Any))
283

@@ -395,9 +395,18 @@ function summarize(io::IO, T::DataType, binding)
if !isempty(subtypes(T))
println(io, "**Subtypes:**")
println(io, "```")
for t in subtypes(T)
sub_types = subtypes(T)
for t in Iterators.take(sub_types, 20)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we hardcode limits like this elsewhere? could maybe be an iocontext property eventually

@omus
Copy link
Member Author

omus commented Apr 22, 2017

I removed the limiting the amount of show subtypes in the help. I'll make another PR for that.

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

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

Nice, I like it. 👍

@@ -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

@omus
Copy link
Member Author

omus commented May 17, 2017

I'll merge this later today unless there are objections.

@omus omus merged commit c2992ac into master May 17, 2017
@omus omus deleted the cv/show_supertypes branch May 17, 2017 22:01
@TotalVerb
Copy link
Contributor

It's a little sad that this is disabled if the type is documented. Is there a way we can get this into help regardless of whether the type is documented?

@StefanKarpinski
Copy link
Member

Personally, I'm in favor of more complete automatic help output for things, including supertypes for types and methods for functions.

@yuyichao
Copy link
Contributor

more complete automatic help output for things, including supertypes for types and methods for functions.

That's exactly what's causing #20904 though....

@StefanKarpinski
Copy link
Member

Yes, well, there are more direct ways to fix that bug than just avoiding triggering it.

@yuyichao
Copy link
Contributor

Ture. What I'm trying to say is that the automatically generated doc isn't very helpful sometimes and it should be possible to manually write documents that are much better. methods, subtypes, methodswith are certainly useful sometimes but I also find it not helping most of the time especially if they take a large fraction of screen space making it harder to find more useful information. I assume this is roughly the rationale behind the current behavior. Integrating them better with the doc system would be good. (paging, filtering, highting, mentioning their existence in the doc of doc system, whatever....) but I don't think we should unconditionally include them.

OTOH though for this particular case, the super type list is likely short so including this unconditionally might be acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants