-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
rewrite show as writemime for Julia v0.4 #219
Conversation
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")
Could you also support the syntax |
Also, might it be easier simply to define a generic Base.writemime{M}(io::IO, ::Type{MIME{M}}, x) = Base.show(io, MIME{M}, x) |
In 0.5, you are supposed to define |
@TotalVerb, Base no longer calls |
@stevengj I meant that it may be possible for that code to be included in There don't seem to be any three-argument |
@@ -438,6 +442,8 @@ function _compat(ex::Expr) | |||
rewrite_pairs_to_tuples!(ex) | |||
elseif VERSION < v"0.4.0-dev+1246" && f == :String | |||
ex = Expr(:call, :bytestring, ex.args[2:end]...) | |||
elseif length(ex.args) == 4 && ex.args[1] === :show |
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.
this should be version dependent otherwise it's calling a deprecated function on 0.5
The below code snippet seems to work in some situations, but sometimes more code is needed for it to work cleanly. It might be better to just to go along with the proposal here, though
|
@TotalVerb: I tried defining the |
I don't think that Julia v0.4 supports a two argument variant of writemime. As a result, support for the two argument version of show inserts an explicit reference to the text/plain MIME type into the argument list.
@dancasimiro Do you have code that demonstrates the problem? I have a similar solution in place on Currencies.jl's master branch, and it works for my (very limited) use case. |
@TotalVerb, that will (a) break I really think we need a |
Point taken. I think the solution in this PR is best then. |
I forgot to add the version check to the import handling check in addition to the function handling.
The new tests that I wrote are passing on 0.3, 0.4, and 0.5. Is there anything else that I need to address before squashing and rebasing? |
I still would like a |
Could you add a short explanation to README.md? |
Show the new @compat support for rewriting "show" as "writemime."
Thanks @dancasimiro! |
Note that we should also have a |
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: