-
-
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
RFC: use IOContext more consistently. part of #14052 #16354
Conversation
I think this also might fix #6117, since |
I see we are currently using |
Biking-shedding |
Yeah, "interactive" may not be the right concept. We can certainly rename it. Jupyter can still turn off limit_output though; that's orthogonal. |
Couldn't that interactive/pager information be obtained via Regarding other variables, it seems that an important issue is whether to print type information or not. The typical use case for that is arrays which can print the type only once, and then use the most compact output possible for elements, vs. printing them individually. Cf. discussion after #14052 (comment) and #15963. |
To clarify, the
|
|
@vtjnash and I were discussing that perhaps |
1851ede
to
08a2841
Compare
Ok, I think things are pretty clean here now. I used the following 3 output flags:
The flags are used in several ways. For example, array elements are always printed with |
@@ -93,7 +93,7 @@ macro enum(T,syms...) | |||
end | |||
end | |||
function Base.show(io::IO,x::$(esc(typename))) | |||
if Base.limit_output(io) | |||
if get(io, :compact, false) |
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 had been writing these as get(io, :compact, false) === true
for future-compatibility / robustness against bad IOContext
settings. Thoughts?
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'd rather get an error when a non-Bool
is passed in the IOContext
than a silent fallback to false
. This makes it easier to detect mistakes.
+1 for Though don't we want another flag to set the amount of information to print (and not only number of digits)? Cf. my comment above. @JeffBezanson, you said at #15454 (comment) that you wanted to support several verbosity levels, which was needed for enums printing (but also e.g. for |
I think it turns out that most verbosity issues need to be factored into separate flags. I don't have a concrete proposal for a verbosity enum, but we can discuss if somebody puts one forward. |
Ok this should be in pretty good shape now. |
For matrix/vector display, having the ability to format all |
Yes, this can be debated. Let's focus on just the changes in this PR first. |
2e44734
to
8005c0f
Compare
travis osx failure log backed up to https://gist.github.com/3cd64fa498b4defbd9a9d72198ddf477, restarted |
We had several `writemime` definitions whose purpose was to control how objects should be printed in the REPL. Instead this introduces a `:multiline` IOContext flag. Use `:compact` IOContext flag to request shorter printing of numbers. Removes `showarray` and `showdict`, allowing IOContext flags to work better recursively. Fixes #13710. Also related: #16103 and #16267.
Should |
EDIT: It can mostly work if the global flag is 3-valued. |
some small tweaks to output function changes and doc updates
I will merge this after CI. |
That AV timeout again. |
FWIW, this (combined with previous PRs) allowed getting rid of about 300 lines of custom printing methods in NullableArrays.jl. Now everything works fine with the default |
BlockArrays, CSV, DataStreams, and TypedTables were all using |
@@ -57,31 +57,33 @@ mimewritable(m::AbstractString, x) = mimewritable(MIME(m), x) | |||
# format and is returned unmodified. This is useful so that raw data can be | |||
# passed to display(m::MIME, x). | |||
|
|||
verbose_writemime(io, m, x) = writemime(IOContext(io,multiline=true,limit=false), m, x) |
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.
Note that this led to JuliaLang/IJulia.jl#462
It's not a big deal; in hindsight, I'm not sure the whole stringmime
function belongs in Base anyway. It should be easy enough to implement a limitstringmime
in IJulia.
The whole output thing is difficult to wrap my head around, but I think I found a nice chunk to bite off.
First,
showarray
andshowdict
were undermining IOContext, so they are removed, making the IOContext flags the only thing that controls printing. That fixes e.g. #13710. It might also fix #16103 and #16267.Second, some definitions of
writemime
were using it to mean "how to print in the REPL", which is not correct. Those needed to be removed in preparation for mergingshow
andwritemime
. Instead I added an:interactive
flag, which picks between e.g. multi-line and single-line display of vectors. REPL display is now done properly, by having the REPL print to an IOContext that sets:limit_output
and:interactive
.The next steps are (1) fully merge show and writemime, (2) decide exactly which output flags we need. (2) is harder than I thought. The important variables currently seem to be:
summary
fit in? Maybe it doesn't, and can stay a separate function.