Skip to content

Commit b501fde

Browse files
committed
lint
1 parent 2c7d1f3 commit b501fde

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

jupyter_server_nbmodel/actions.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
...
3838

3939

40-
# FIXME should we use caching to retrieve faster at least the document
40+
# FIXME should we use caching to retrieve faster at least the document.
4141
async def _get_ycell(
4242
ydoc: jupyter_server_ydoc.app.YDocExtension | None,
4343
metadata: dict | None,
@@ -54,26 +54,20 @@ async def _get_ycell(
5454
msg = "jupyter-collaboration extension is not installed on the server. Outputs won't be written within the document." # noqa: E501
5555
get_logger().warning(msg)
5656
return None
57-
5857
document_id = metadata.get("document_id")
5958
cell_id = metadata.get("cell_id")
60-
6159
if document_id is None or cell_id is None:
6260
msg = (
6361
"document_id and cell_id not defined. The outputs won't be written within the document."
6462
)
6563
get_logger().debug(msg)
6664
return None
67-
6865
notebook: YNotebook | None = await ydoc.get_document(room_id=document_id, copy=False)
69-
7066
if notebook is None:
7167
msg = f"Document with ID {document_id} not found."
7268
get_logger().warning(msg)
7369
return None
74-
7570
ycells = filter(lambda c: c["id"] == cell_id, notebook.ycells)
76-
7771
ycell = next(ycells, None)
7872
if ycell is None:
7973
msg = f"Cell with ID {cell_id} not found in document {document_id}."
@@ -83,7 +77,6 @@ async def _get_ycell(
8377
# Check if there is more than one cell
8478
if next(ycells, None) is not None:
8579
get_logger().warning("Multiple cells have the same ID '%s'.", cell_id)
86-
8780
if ycell["cell_type"] != "code":
8881
msg = f"Cell with ID {cell_id} of document {document_id} is not of type code."
8982
get_logger().error(msg)
@@ -106,17 +99,14 @@ def _output_hook(outputs: list[NotebookNode], ycell: y.Map | None, msg: dict) ->
10699
# FIXME support for version
107100
output = nbformat.v4.output_from_msg(msg)
108101
outputs.append(output)
109-
110102
if ycell is not None:
111103
cell_outputs = ycell["outputs"]
112104
if msg_type == "stream":
113105
with cell_outputs.doc.transaction():
114106
text = output["text"]
115-
116107
# FIXME Logic is quite complex at https://github.com/jupyterlab/jupyterlab/blob/7ae2d436fc410b0cff51042a3350ba71f54f4445/packages/outputarea/src/model.ts#L518
117108
if text.endswith((os.linesep, "\n")):
118109
text = text[:-1]
119-
120110
if (not cell_outputs) or (cell_outputs[-1]["name"] != output["name"]):
121111
output["text"] = [text]
122112
cell_outputs.append(output)
@@ -127,14 +117,11 @@ def _output_hook(outputs: list[NotebookNode], ycell: y.Map | None, msg: dict) ->
127117
else:
128118
with cell_outputs.doc.transaction():
129119
cell_outputs.append(output)
130-
131120
elif msg_type == "clear_output":
132121
# FIXME msg.content.wait - if true should clear at the next message
133122
outputs.clear()
134-
135123
if ycell is not None:
136124
del ycell["outputs"][:]
137-
138125
elif msg_type == "update_display_data":
139126
# FIXME
140127
...
@@ -157,7 +144,6 @@ def _stdin_hook(kernel_id: str, request_id: str, pending_input: PendingInput, ms
157144
get_logger().error(
158145
f"Execution request {kernel_id} received a input request while waiting for an input.\n{msg}" # noqa: E501
159146
)
160-
161147
header = msg["header"].copy()
162148
header["date"] = header["date"].isoformat()
163149
pending_input.request_id = request_id
@@ -222,7 +208,6 @@ async def _execute_snippet(
222208
}
223209
)
224210
outputs = []
225-
226211
# FIXME we don't check if the session is consistent (aka the kernel is linked to the document)
227212
# - should we?
228213
reply = await ensure_async(
@@ -233,9 +218,7 @@ async def _execute_snippet(
233218
stdin_hook=stdin_hook if client.allow_stdin else None,
234219
)
235220
)
236-
237221
reply_content = reply["content"]
238-
239222
if ycell is not None:
240223
execution_end_time = datetime.now(timezone.utc).isoformat()[:-6]
241224
with ycell.doc.transaction():
@@ -289,7 +272,6 @@ async def kernel_worker(
289272
results[uid] = await _execute_snippet(
290273
client, ydoc, snippet, metadata, partial(_stdin_hook, kernel_id, uid, pending_input)
291274
)
292-
293275
queue.task_done()
294276
get_logger().debug(f"Execution request {uid} processed for kernel {kernel_id}.")
295277
except (asyncio.CancelledError, KeyboardInterrupt, RuntimeError) as e:
@@ -307,6 +289,5 @@ async def kernel_worker(
307289
)
308290
if not queue.empty():
309291
queue.task_done()
310-
311292
if to_raise is not None:
312293
raise to_raise

0 commit comments

Comments
 (0)