{"record":{"id":"83f1e0ab24eb6c09","repo":"can1357/oh-my-pi","slug":"display-raw-true-requires-a-mime-bundle-dict","errorCode":null,"errorMessage":"display(..., raw=True) requires a MIME bundle dict","messagePattern":"display\\(\\.\\.\\., raw=True\\) requires a MIME bundle dict","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/eval/py/runner.py","lineNumber":990,"sourceCode":"        try:\n            bundle[\"text/plain\"] = repr(value)\n        except Exception:\n            bundle[\"text/plain\"] = f\"<unrepr {type(value).__name__}>\"\n\n    return bundle\n\n\ndef _emit_display(bundle: dict, *, kind: str = \"display\") -> None:\n    rid = _CURRENT_RID.get()\n    if rid is None:\n        return\n    _emit({\"type\": kind, \"id\": rid, \"bundle\": bundle})\n\n\ndef __omp_display(value: Any, *, raw: bool = False, kind: str = \"display\") -> None:\n    if raw:\n        if not isinstance(value, dict):\n            raise TypeError(\"display(..., raw=True) requires a MIME bundle dict\")\n        bundle = {str(k): v for k, v in value.items()}\n        if \"text/plain\" not in bundle:\n            bundle[\"text/plain\"] = \"\"\n        _emit_display(bundle, kind=kind)\n        return\n    _emit_display(_mime_bundle(value), kind=kind)\n\n\n# ---------------------------------------------------------------------------\n# Matplotlib post-cell flush\n# ---------------------------------------------------------------------------\n\n\ndef _flush_matplotlib_figures() -> None:\n    plt = sys.modules.get(\"matplotlib.pyplot\")\n    if plt is None:\n        return\n    try:","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/eval/py/runner.py#L972-L1008","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a real dict: display({'text/plain': 'hi', 'text/html': '<b>hi</b>'}, raw=True)","Drop raw=True and let _mime_bundle convert the object automatically","Ensure keys are dict keys (they will be coerced to str) with MIME-type names"],"exampleFix":"// before\ndisplay(\"<b>hi</b>\", raw=True)\n// after\ndisplay({\"text/html\": \"<b>hi</b>\", \"text/plain\": \"hi\"}, raw=True)","handlingStrategy":"type-guard","validationCode":"if raw and not isinstance(value, dict):\n    raise TypeError(\"raw=True requires a MIME bundle dict\")","typeGuard":"def is_mime_bundle(v) -> bool:\n    return isinstance(v, dict) and all(isinstance(k, str) for k in v)","tryCatchPattern":"try:\n    display(value, raw=True)\nexcept TypeError as e:\n    if \"MIME bundle dict\" in str(e):\n        display(value)  # non-raw auto-converts via _mime_bundle","preventionTips":["Only use raw=True with hand-built dicts keyed by MIME type","Default to non-raw display for arbitrary objects","Include a 'text/plain' fallback in hand-built bundles"],"tags":["python","typeerror","display"],"backgroundTag":"mime-bundle-type-error","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}