-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
clarify show
doc strings
#36076
clarify show
doc strings
#36076
Conversation
base/show.jl
Outdated
To customize human-readable text output for objects of type `T`, define | ||
`show(io::IO, ::MIME"text/plain", ::T)` instead. To customize how objects | ||
are shown inside containers, check the `:compact` [`IOContext`](@ref) | ||
property of `io`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice if we could simply say
property of `io`. | |
property of `io` in `show(io::IO, ::MIME"text/plain", ::T)`. |
However, current situation is complicated because
- non-vector arrays call 3-arg
show
and then fallback to 2-argshow
, with:compact => true
set. - vectors do the same but without setting
:compact => true
. - dictionaries and sets use 2-arg
show
.
Maybe it's better to be honest and say that there are some rough edges in show
system with containers and there is no consistent way to control how items with custom items are shown. I do still think we should be using show(IOContext(io, :compact => true), "text/plain", element)
consistently everywhere in 3-arg show
of containers but it cannot block 1.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to reword this. We shouldn't think of it as controlling how your type is displayed inside a container --- that can never fully work, because it will always depend on what the container does. All you really need to know is "MIME type = human readable, 2-arg = parseable, compact = keep it short". For example, matrices call 3-arg show because they are themselves using a human-readable output format. But if some other container only has a parseable representation, then its elements will use 2-arg show.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All you really need to know is "MIME type = human readable, 2-arg = parseable, compact = keep it short".
Yes, that's the ideal situation. It'd be great if we can orthogonalize target reader ("machines" vs humans) and the compactness of the output. The reason why I suggested to add "in show(io::IO, ::MIME"text/plain", ::T)
" was that I thought this paragraph was about human-readable format (as that's how it starts).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for documenting this.
fixes #36072