@@ -32,6 +32,8 @@ def timestamp() -> str:
32
32
return datetime .datetime .utcnow ().isoformat () + 'Z'
33
33
34
34
35
+ MD_EXPRESSIONS_PREFIX = "md-expr"
36
+
35
37
class NotebookClient (LoggingConfigurable ):
36
38
"""
37
39
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.
1030
1032
self .kc .execute (
1031
1033
'' ,
1032
1034
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 )},
1034
1036
)
1035
1037
)
1036
1038
task_poll_kernel_alive = asyncio .ensure_future (
@@ -1061,7 +1063,10 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
1061
1063
raise
1062
1064
self ._check_raise_for_error (cell , exec_reply )
1063
1065
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 )
1065
1070
self .nb ['cells' ][cell_index ] = cell
1066
1071
return cell
1067
1072
0 commit comments