-
-
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
Deprecate showcompact() #26080
Deprecate showcompact() #26080
Conversation
NEWS.md
Outdated
|
||
* `showcompact(io, x...)` has been deprecated in favor of | ||
`show(IOContext(io, :compact => true), x...)` ([#26080]). | ||
Use `sprint(showcompact, x...)` instead of `sprint(show, x..., context=:compact => true)`. |
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.
That's the wrong way around, isn't it?
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. I had originally written "is deprecated in favor of", but I changed it because it's not really a separate deprecation, mostly an advice. Will fix in the next round.
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.
Fixed.
The downside is this has to allocate a new IOContext on every call, but I guess that's life. |
|
||
Call the given function with an I/O stream and the supplied extra arguments. | ||
Everything written to this I/O stream is returned as a string. | ||
`context` can be either an [`IOContext`](@ref) whose properties will be used, | ||
or a `Pair` specifying a property and its value. `sizehint` suggests the capacity |
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.
Specifying a Pair does happen to work, but only the usage case of passing an IO was what I had really originally intended (and found to be common).
I think that we maybe instead should suggest the usage of anonymous functions as a general way of passing a configuration set of arbitrarily many new properties:
showcompact = (io, v) -> show(IOContext(io, :compact => true), v)
sprint(showcompact, 66.66666)
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.
OK. I assumed it was intended since the signature doesn't use ::IOContext
.
I actually started with the anonymous function approach, but it's quite verbose and much less convenient than passing a pair for common cases (have a look at the diff to get and idea). So I'd say we'd better continue to support passing a pair.
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 don't intend to prevent passing a Pair, but it simply doesn't generalize as well. Although I suppose it also quickly becomes easier just to write it out:
buf = IOBuffer(sizehint = sizehint)
io = IOContext(buf, :compact => true)
show(io, 66.66666)
return String(take!(buf))
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.
My thought was that passing a single pair is the most common case, and for other situations it's not too hard to create a full IOContext
.
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 agree it's very nice to be able to pass a single pair.
c88a1ff
to
daf2846
Compare
If people are concerned about the |
Triage is in favor of removing |
There is no obvious reason to provide a special function for the :compact IOContext property but not for other properties. showcompact() used to be useful to print a single-line representation of an array at the REPL, but now show() does the same thing. So it should only be needed for collections to print their elements when implementing show(), and for tests (most of the changes here). Also improve a few docstrings.
daf2846
to
e2b151f
Compare
I've rebased and added a short presentation of |
LGTM! |
There is no obvious reason to provide a special function for the
:compact
IOContext
propertybut not for other properties.
showcompact
used to be useful to print a single-line representation of an array at the REPL, but nowshow
does the same thing. So it should only be needed for collections to print their elements when implementingshow
, and for tests (most of the changes here).Also improve a few docstrings.