@@ -41,6 +41,8 @@ def timestamp() -> str:
41
41
return datetime .datetime .utcnow ().isoformat () + 'Z'
42
42
43
43
44
+ MD_EXPRESSIONS_PREFIX = "md-expr"
45
+
44
46
class NotebookClient (LoggingConfigurable ):
45
47
"""
46
48
Encompasses a Client for executing cells in a notebook
@@ -1054,7 +1056,7 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
1054
1056
self .kc .execute (
1055
1057
'' ,
1056
1058
silent = True ,
1057
- user_expressions = {f"md-expr -{ i } " : expr for i , expr in enumerate (expressions )},
1059
+ user_expressions = {f"{ MD_EXPRESSIONS_PREFIX } -{ i } " : expr for i , expr in enumerate (expressions )},
1058
1060
)
1059
1061
)
1060
1062
task_poll_kernel_alive = asyncio .ensure_future (
@@ -1085,7 +1087,10 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
1085
1087
raise
1086
1088
self ._check_raise_for_error (cell , exec_reply )
1087
1089
attachments = {key : val ["data" ] for key , val in exec_reply ["content" ]["user_expressions" ].items ()}
1088
- cell .setdefault ("attachments" , {}).update (attachments )
1090
+ cell .setdefault ("attachments" , {})
1091
+ # remove old expressions from cell
1092
+ cell ["attachments" ] = {key : val for key , val in cell ["attachments" ].items () if not key .startswith (MD_EXPRESSIONS_PREFIX )}
1093
+ cell ["attachments" ].update (attachments )
1089
1094
self .nb ['cells' ][cell_index ] = cell
1090
1095
return cell
1091
1096
0 commit comments