From b70f3b09b5df9cf6071919956ead6b922723fcfb Mon Sep 17 00:00:00 2001 From: Joshua James Venter <25530194@sun.ac.za> Date: Sun, 3 Dec 2023 14:23:48 +0200 Subject: [PATCH 1/3] Refactor execute_request to reduce redundancy and improve consistency --- ipykernel/kernelbase.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ipykernel/kernelbase.py b/ipykernel/kernelbase.py index bd3fb074..f9eb2b94 100644 --- a/ipykernel/kernelbase.py +++ b/ipykernel/kernelbase.py @@ -283,6 +283,11 @@ def __init__(self, **kwargs): self.control_queue: Queue[t.Any] = Queue() + # Storing the accepted parameters for do_execute, used in execute_request + self._do_exec_accepted_params = _accepts_parameters( + self.do_execute, ["cell_meta", "cell_id"] + ) + def dispatch_control(self, msg): self.control_queue.put_nowait(msg) @@ -724,6 +729,8 @@ async def execute_request(self, stream, ident, parent): store_history = content.get("store_history", not silent) user_expressions = content.get("user_expressions", {}) allow_stdin = content.get("allow_stdin", False) + cell_meta = parent.get("metadata", {}) + cell_id = cell_meta.get("cellId") except Exception: self.log.error("Got bad msg: ") self.log.error("%s", parent) @@ -739,12 +746,6 @@ async def execute_request(self, stream, ident, parent): self.execution_count += 1 self._publish_execute_input(code, parent, self.execution_count) - cell_meta = parent.get("metadata", {}) - cell_id = cell_meta.get("cellId") - - # Check which parameters do_execute can accept - accepts_params = _accepts_parameters(self.do_execute, ["cell_meta", "cell_id"]) - # Arguments based on the do_execute signature do_execute_args = { "code": code, @@ -754,9 +755,9 @@ async def execute_request(self, stream, ident, parent): "allow_stdin": allow_stdin, } - if accepts_params["cell_meta"]: + if self._do_exec_accepted_params["cell_meta"]: do_execute_args["cell_meta"] = cell_meta - if accepts_params["cell_id"]: + if self._do_exec_accepted_params["cell_id"]: do_execute_args["cell_id"] = cell_id # Call do_execute with the appropriate arguments From 4296683070408350f6c548f860a121f948dddcb5 Mon Sep 17 00:00:00 2001 From: Joshua James Venter <25530194@sun.ac.za> Date: Sun, 3 Dec 2023 18:58:24 +0200 Subject: [PATCH 2/3] Trigger CI From a7709ea17babb0ea2e2d4e415d985371bb1dcec0 Mon Sep 17 00:00:00 2001 From: Joshua James Venter <25530194@sun.ac.za> Date: Sun, 3 Dec 2023 21:57:26 +0200 Subject: [PATCH 3/3] Trigger CI with updated pytest v0.23.1