From e4ede7e98609bc1e2996c055a3df615d8b557419 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 20 Jul 2023 14:03:05 +0200 Subject: [PATCH] feat: let display hook handle clear_output A display hook can handle a publish message, but not yet a clear_output Upstreaming of: https://github.com/widgetti/solara/pull/132 Follow up of: https://github.com/ipython/ipykernel/pull/1110 Related: https://github.com/ipython/ipykernel/pull/115/files Would enable https://github.com/jupyter-widgets/ipywidgets/pull/3759 to fully work kernel side. --- ipykernel/zmqshell.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ipykernel/zmqshell.py b/ipykernel/zmqshell.py index 9455b8f74..61c5ee69b 100644 --- a/ipykernel/zmqshell.py +++ b/ipykernel/zmqshell.py @@ -144,11 +144,17 @@ def clear_output(self, wait=False): """ content = dict(wait=wait) self._flush_streams() + msg = self.session.msg("clear_output", json_clean(content), parent=self.parent_header) + + # see publish() for details on how this works + for hook in self._hooks: + msg = hook(msg) + if msg is None: + return + self.session.send( self.pub_socket, - "clear_output", - content, - parent=self.parent_header, + msg, ident=self.topic, )