can1357/oh-my-pi · error · TypeError

display(..., raw=True) requires a MIME bundle dict

Error message

display(..., raw=True) requires a MIME bundle dict

What it means

display() with raw=True expects the caller to supply a pre-built MIME bundle dict (keys like 'text/plain', 'text/html'). If the value is not a dict, it raises TypeError. Non-raw calls are routed through _mime_bundle() conversion instead, so this only affects raw mode.

Source

Thrown at packages/coding-agent/src/eval/py/runner.py:990

        try:
            bundle["text/plain"] = repr(value)
        except Exception:
            bundle["text/plain"] = f"<unrepr {type(value).__name__}>"

    return bundle


def _emit_display(bundle: dict, *, kind: str = "display") -> None:
    rid = _CURRENT_RID.get()
    if rid is None:
        return
    _emit({"type": kind, "id": rid, "bundle": bundle})


def __omp_display(value: Any, *, raw: bool = False, kind: str = "display") -> None:
    if raw:
        if not isinstance(value, dict):
            raise TypeError("display(..., raw=True) requires a MIME bundle dict")
        bundle = {str(k): v for k, v in value.items()}
        if "text/plain" not in bundle:
            bundle["text/plain"] = ""
        _emit_display(bundle, kind=kind)
        return
    _emit_display(_mime_bundle(value), kind=kind)


# ---------------------------------------------------------------------------
# Matplotlib post-cell flush
# ---------------------------------------------------------------------------


def _flush_matplotlib_figures() -> None:
    plt = sys.modules.get("matplotlib.pyplot")
    if plt is None:
        return
    try:

View on GitHub (pinned to 9690622007)

Solutions

  1. Pass a real dict: display({'text/plain': 'hi', 'text/html': '<b>hi</b>'}, raw=True)
  2. Drop raw=True and let _mime_bundle convert the object automatically
  3. Ensure keys are dict keys (they will be coerced to str) with MIME-type names

Example fix

// before
display("<b>hi</b>", raw=True)
// after
display({"text/html": "<b>hi</b>", "text/plain": "hi"}, raw=True)
Defensive patterns

Strategy: type-guard

Validate before calling

if raw and not isinstance(value, dict):
    raise TypeError("raw=True requires a MIME bundle dict")

Type guard

def is_mime_bundle(v) -> bool:
    return isinstance(v, dict) and all(isinstance(k, str) for k in v)

Try / catch

try:
    display(value, raw=True)
except TypeError as e:
    if "MIME bundle dict" in str(e):
        display(value)  # non-raw auto-converts via _mime_bundle

Prevention

When it happens

Trigger: Calling display(value, raw=True) where value is a str, object, or list rather than a dict — e.g. display(obj, raw=True) hoping to bypass MIME conversion.

Common situations: Copying IPython's display(raw=True) usage incorrectly, hand-building bundles as lists of tuples, or forgetting to drop raw=True when passing a plain object.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/83f1e0ab24eb6c09. Report an issue: GitHub.