Skip to content
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 writemime to methods of show #16563

Merged
merged 1 commit into from
May 27, 2016
Merged

Conversation

JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented May 24, 2016

This is the next bit of #14052.

The one slight wart is that text/plain showing defaults to calling show with 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.

@JeffBezanson JeffBezanson force-pushed the jb/writemime_to_show branch 2 times, most recently from 8272e02 to 0c010e5 Compare May 24, 2016 19:36

.. 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("")}``\ .)
Copy link
Contributor

@Tetralux Tetralux May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is only necessary to define a new show method for T\ , via: ``show(stream, ::MIME"mime", x::T)

Mention that users who want to overload show for text/plain should overload the 2-arg version?

Copy link
Contributor

@Tetralux Tetralux May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, it's mentioned below at L716.
Mention the text/plain fallback, immediately after this (the above) quote instead? 😄


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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 2-argument show(stream::IO, x::MyType) method.

@JeffBezanson JeffBezanson merged commit 692618f into master May 27, 2016
@JeffBezanson JeffBezanson deleted the jb/writemime_to_show branch May 27, 2016 05:50
@stevengj
Copy link
Member

Is this breaking? If a module defines writemime, will that now be silently ignored?

@JeffBezanson
Copy link
Member Author

Ah, it looks like I should have used deprecate_binding. Then it should work.

@stevengj
Copy link
Member

Thanks! (fixed in d42585c)

@dancasimiro
Copy link
Contributor

How do I support Julia v0.4 and v0.5 in a package? Will support be added to Compat?

@stevengj
Copy link
Member

Yes, @compat will have to do it.

dancasimiro added a commit to dancasimiro/Compat.jl that referenced this pull request Jun 2, 2016
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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants