Skip to content

Commit a245b38

Browse files
author
Christopher Doris
committed
discover mime types to bundle
1 parent d0d2afc commit a245b38

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/cpython/juliaany.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,19 @@ pyjlany_repr_mimebundle(xo::PyPtr, args::PyPtr, kwargs::PyPtr) = begin
382382
ism1(PyArg_GetArg(Union{Set{String},Nothing}, "_repr_mimebundle_", kwargs, "exclude", nothing)) && return PyNULL
383383
exc = takeresult(Union{Set{String},Nothing})
384384
# decide which mimes to include
385-
mimes = inc === nothing ? ALL_MIMES : push!(inc, "text/plain")
385+
if inc === nothing
386+
# default set of mimes to try
387+
mimes = copy(ALL_MIMES)
388+
# looks for mimes on show methods for the type
389+
for meth in methods(show, Tuple{IO, MIME, typeof(x)}).ms
390+
mimetype = meth.sig.parameters[3]
391+
mimetype isa DataType || continue
392+
mime = string(mimetype.parameters[1])
393+
push!(mimes, mime)
394+
end
395+
else
396+
mimes = push!(inc, "text/plain")
397+
end
386398
exc === nothing || setdiff!(mimes, exc)
387399
# make the bundle
388400
bundle = PyDict_New()

0 commit comments

Comments
 (0)