Patches the ipdb debugger to enable rich output (e.g. with treescope).

displayhook is the method that is called to print outputs in PDB to the console. This isn’t a documented attribute on pdb.PDB but overriding it appears to work correctly.

This patch is fairly unergonomic, since it directly rewrites methods on the IPython Pdb class. However, modifying this displayhook is otherwise fairly complex, since the debugger class is hardcoded in various places to enable IPython magics like %debug. This also has the advantage of automatically patching all subclasses of IPython’s debugger as well (unless they specifically override the displayhook).

Note that this will only use penzai.treescope if treescope has been registered as the default IPython display hook, using pz.ts.register_as_default()


displayhook_with_ipython(self, obj)

Custom displayhook to display results with IPython.


Patches the IPython debugger to use IPython.display.display.


Unpatches the IPython debugger so that it uses its original displayhook.