deprecate writemime to methods of show#16563
Conversation
8272e02 to
0c010e5
Compare
| .. Docstring generated from Julia source | ||
|
|
||
| The ``display`` functions ultimately call ``writemime`` in order to write an object ``x`` as a given ``mime`` type to a given I/O ``stream`` (usually a memory buffer), if possible. In order to provide a rich multimedia representation of a user-defined type ``T``\ , it is only necessary to define a new ``writemime`` method for ``T``\ , via: ``writemime(stream, ::MIME"mime", x::T) = ...``\ , where ``mime`` is a MIME-type string and the function body calls ``write`` (or similar) to write that representation of ``x`` to ``stream``\ . (Note that the ``MIME""`` notation only supports literal strings; to construct ``MIME`` types in a more flexible manner use ``MIME{Symbol("")}``\ .) | ||
| The ``display`` functions ultimately call ``show`` in order to write an object ``x`` as a given ``mime`` type to a given I/O ``stream`` (usually a memory buffer), if possible. In order to provide a rich multimedia representation of a user-defined type ``T``\ , it is only necessary to define a new ``show`` method for ``T``\ , via: ``show(stream, ::MIME"mime", x::T) = ...``\ , where ``mime`` is a MIME-type string and the function body calls ``write`` (or similar) to write that representation of ``x`` to ``stream``\ . (Note that the ``MIME""`` notation only supports literal strings; to construct ``MIME`` types in a more flexible manner use ``MIME{Symbol("")}``\ .) |
There was a problem hiding this comment.
it is only necessary to define a new
showmethod forT\ , via: ``show(stream, ::MIME"mime", x::T)
Mention that users who want to overload show for text/plain should overload the 2-arg version?
There was a problem hiding this comment.
Wait, it's mentioned below at L716.
Mention the text/plain fallback, immediately after this (the above) quote instead? 😄
0c010e5 to
4bf2872
Compare
base/docs/helpdb/Base.jl
Outdated
|
|
||
| The default MIME type is `MIME"text/plain"`. There is a fallback definition for `text/plain` | ||
| output that calls `show` with 2 arguments. Therefore, this case should be handled by | ||
| defining a 2-argument `show` method. |
There was a problem hiding this comment.
A 2-argument show(stream::IO, x::MyType) method.
4bf2872 to
ae62bf0
Compare
|
Is this breaking? If a module defines writemime, will that now be silently ignored? |
|
Ah, it looks like I should have used deprecate_binding. Then it should work. |
|
Thanks! (fixed in d42585c) |
|
How do I support Julia v0.4 and v0.5 in a package? Will support be added to Compat? |
|
Yes, |
writemime was deprecated in JuliaLang/julia#16563 in julia commit ae62bf0b813afbf32402874451e55d16de909bd4. This compatibility change allows code that is written in the Julia v0.5 style to continue working on Julia v0.4. I have not tested this on Julia v0.3. The @compat macro must be used on the import statement and the function definition. For example: @compat import Base.show @compat show(io::IO, ::MIME"text/plain", ::TestCustomShowType) = print(io, "MyTestCustomShowType")
This is the next bit of #14052.
The one slight wart is that text/plain showing defaults to calling
showwith 2 arguments, so you should never define text/plain showing directly, but instead just add a 2-argument method.Which reminds me to update the docs.done.