@@ -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+
394407pyjlany_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 ()
0 commit comments