Skip to content

Commit edbe89c

Browse files
author
Christopher Doris
committed
bugfix: display broken in ipython
1 parent 4f24812 commit edbe89c

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/cpython/juliaany.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ const ALL_MIMES = [
391391
"video/webm",
392392
]
393393

394+
mimes_for(@nospecialize(x)) = begin
395+
# default mimes we always try
396+
mimes = copy(ALL_MIMES)
397+
# look for mimes on show methods for this type
398+
for meth in methods(show, Tuple{IO, MIME, typeof(x)}).ms
399+
mimetype = meth.sig.parameters[3]
400+
mimetype isa DataType || continue
401+
mime = string(mimetype.parameters[1])
402+
push!(mimes, mime)
403+
end
404+
return mimes
405+
end
406+
394407
pyjlany_repr_mimebundle(xo::PyPtr, args::PyPtr, kwargs::PyPtr) = begin
395408
x = PyJuliaValue_GetValue(xo)
396409
ism1(PyArg_CheckNumArgsEq("_repr_mimebundle_", args, 0)) && return PyNULL
@@ -399,19 +412,8 @@ pyjlany_repr_mimebundle(xo::PyPtr, args::PyPtr, kwargs::PyPtr) = begin
399412
ism1(PyArg_GetArg(Union{Set{String},Nothing}, "_repr_mimebundle_", kwargs, "exclude", nothing)) && return PyNULL
400413
exc = takeresult(Union{Set{String},Nothing})
401414
# decide which mimes to include
402-
if inc === nothing
403-
# default set of mimes to try
404-
mimes = copy(ALL_MIMES)
405-
# looks for mimes on show methods for the type
406-
for meth in methods(show, Tuple{IO, MIME, typeof(x)}).ms
407-
mimetype = meth.sig.parameters[3]
408-
mimetype isa DataType || continue
409-
mime = string(mimetype.parameters[1])
410-
push!(mimes, mime)
411-
end
412-
else
413-
mimes = push!(inc, "text/plain")
414-
end
415+
mimes = inc === nothing ? mimes_for(x) : push!(inc, "text/plain")
416+
# respect exclude
415417
exc === nothing || setdiff!(mimes, exc)
416418
# make the bundle
417419
bundle = PyDict_New()

src/ipython.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Base.display(d::IPythonDisplay, @nospecialize(x)) = begin
1919
end
2020
buf = IOBuffer()
2121
dict = pydict()
22-
for (m, _) in [_py_mimes; (MIME"text/plain", "")]
22+
for m in C.mimes_for(x)
2323
try
24-
show(buf, m(), x)
24+
show(buf, MIME(m), x)
2525
catch
2626
continue
2727
end
2828
data = take!(buf)
29-
dict[string(m())] = istextmime(m()) ? pystr(data) : pybytes(data)
29+
dict[m] = istextmime(m) ? pystr(data) : pybytes(data)
3030
end
3131
length(dict) == 0 && throw(MethodError(display, (d, x)))
3232
try

0 commit comments

Comments
 (0)