@@ -32,6 +32,8 @@ def timestamp() -> str:
3232 return datetime .datetime .utcnow ().isoformat () + 'Z'
3333
3434
35+ MD_EXPRESSIONS_PREFIX = "md-expr"
36+
3537class NotebookClient (LoggingConfigurable ):
3638 """
3739 Encompasses a Client for executing cells in a notebook
@@ -1030,7 +1032,7 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
10301032 self .kc .execute (
10311033 '' ,
10321034 silent = True ,
1033- user_expressions = {f"md-expr -{ i } " : expr for i , expr in enumerate (expressions )},
1035+ user_expressions = {f"{ MD_EXPRESSIONS_PREFIX } -{ i } " : expr for i , expr in enumerate (expressions )},
10341036 )
10351037 )
10361038 task_poll_kernel_alive = asyncio .ensure_future (
@@ -1061,7 +1063,10 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
10611063 raise
10621064 self ._check_raise_for_error (cell , exec_reply )
10631065 attachments = {key : val ["data" ] for key , val in exec_reply ["content" ]["user_expressions" ].items ()}
1064- cell .setdefault ("attachments" , {}).update (attachments )
1066+ cell .setdefault ("attachments" , {})
1067+ # remove old expressions from cell
1068+ cell ["attachments" ] = {key : val for key , val in cell ["attachments" ].items () if not key .startswith (MD_EXPRESSIONS_PREFIX )}
1069+ cell ["attachments" ].update (attachments )
10651070 self .nb ['cells' ][cell_index ] = cell
10661071 return cell
10671072
0 commit comments