-
-
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
show(io, x) vs show(io, "text/plain", x) -- docs? #18004
Comments
We did it that way originally; the attribute was called |
aha! I did run into this a couple of times and was kinda confused what I was doing wrong (I am confused easily). Not complaining here though, never was a serious issue for what I was trying to do. Just confirming that some people do indeed run into this in practice |
Okay, maybe it just needs to be documented, then? |
The situation has changed a bit since this issue was filed, but the problem remains. What has changed is that we now have a fallback: show(io::IO, ::MIME"text/plain", x) = show(io, x) Yet, the manual still recommends overloading the two-argument
I find this approach confusing given that it parallels the The argument against this which justified the removal of the I think that using an |
Almost all user types are containers for other types. This means that multiline=false will potentially have to be set in a huge number of places. In fact, arguably all calls to |
Correct, that is why |
I would also prefer not to flip-flop on this. In practice, this would have the effect of expanding 2 forms of |
OK. So that means we consider that the multi-line/single-line distinction doesn't make sense for formats other than plain text? Or maybe the difference between the two-argument and the three-argument |
No, there's nothing particularly special about plain-text output, other than (like the "text/plain" mime type) being the default (and, specifically, to output utf8-encoded content). I created an example of an HTML stream (text/html mime type) as part of my research during creation of the IOContext concept (https://github.com/JuliaLang/julia/compare/jn/iocolor#diff-c20eb2eead14027fab4293e10bacf73bR398). The difference as actually more obvious with complex formats, where two-arg show renders only a portion of a document (such as some HTML formatting tags), while three-arg show is expected to render a completed document (such as adding <head/><body/>). |
Sorry, I don't really understand your example. What I meant is that there's no way to request printing a custom type using a single or multiple lines in the |
Correct; there is no such thing as requesting multi-line output. What we have instead is methods with a MIME type, and those without. |
Then can we find better guidelines regarding what kind of output the method without a MIME type should produce compared to those with a MIME type? As I noted above, the manual still mentions multi-line output as a difference. |
The manual states that since the default
show(io, "text/plain", x)
calls through toshow(io, x)
, all you ever have to define is the latter. However, this doesn't seem to be quite true.In particular, the REPL calls
display(x)
which callsshow(io, "text/plain", x)
, notshow(io, x)
, and the array display exploits this to output a "2d" representation of a matrix in the REPL by callingshowarray(io, x, false)
fromshow(io, "text/plain", x)
, whereas it separately overloadsshow(io, x)
to callshowarray(io, x, true)
and get a "1d" representation of a matrix forprint
and friends.This trick is not documented, and seems contrary to the spirit of #14052. Maybe
display
should callshow(IOContext(io, someattribute=true), "text/plain", x)
for some attribute that indicates that a "display" version ofx
is desired?cc @vtjnash
The text was updated successfully, but these errors were encountered: