From c8135f439cf6cc53925cbd0eecff60c3d530356b Mon Sep 17 00:00:00 2001 From: Eric Rawn Date: Tue, 11 Nov 2025 20:11:13 -0800 Subject: [PATCH 1/2] pass cell_meta from do_execute to run_cell --- ipykernel/ipkernel.py | 22 ++++++++++------------ tests/inprocess/test_kernel.py | 5 +++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index e1505a9a7..0b45dc2e4 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -386,7 +386,7 @@ async def do_execute( if hasattr(shell, "run_cell_async") and hasattr(shell, "should_run_async"): run_cell = shell.run_cell_async should_run_async = shell.should_run_async - accepts_params = _accepts_parameters(run_cell, ["cell_id"]) + accepts_params = _accepts_parameters(run_cell, ["cell_id", "cell_meta"]) else: should_run_async = lambda cell: False # noqa: ARG005, E731 # older IPython, @@ -395,7 +395,7 @@ async def do_execute( async def run_cell(*args, **kwargs): return shell.run_cell(*args, **kwargs) - accepts_params = _accepts_parameters(shell.run_cell, ["cell_id"]) + accepts_params = _accepts_parameters(shell.run_cell, ["cell_id", "cell_meta"]) try: # default case: runner is asyncio and asyncio is already running # TODO: this should check every case for "are we inside the runner", @@ -406,6 +406,11 @@ async def run_cell(*args, **kwargs): except Exception: transformed_cell = code preprocessing_exc_tuple = sys.exc_info() + do_execute_args = {} + if accepts_params["cell_meta"]: + do_execute_args["cell_meta"] = cell_meta + if self._do_exec_accepted_params["cell_id"]: + do_execute_args["cell_id"] = cell_id if ( _asyncio_runner # type:ignore[truthy-bool] @@ -424,7 +429,7 @@ async def run_cell(*args, **kwargs): silent=silent, transformed_cell=transformed_cell, preprocessing_exc_tuple=preprocessing_exc_tuple, - cell_id=cell_id, + **do_execute_args, ) else: coro = run_cell( @@ -433,6 +438,7 @@ async def run_cell(*args, **kwargs): silent=silent, transformed_cell=transformed_cell, preprocessing_exc_tuple=preprocessing_exc_tuple, + **do_execute_args, ) coro_future = asyncio.ensure_future(coro) @@ -454,15 +460,7 @@ async def run_cell(*args, **kwargs): # runner isn't already running, # make synchronous call, # letting shell dispatch to loop runners - if accepts_params["cell_id"]: - res = shell.run_cell( - code, - store_history=store_history, - silent=silent, - cell_id=cell_id, - ) - else: - res = shell.run_cell(code, store_history=store_history, silent=silent) + res = shell.run_cell(code, store_history=store_history, silent=silent, **do_execute_args) finally: self._restore_input() diff --git a/tests/inprocess/test_kernel.py b/tests/inprocess/test_kernel.py index b965d9b89..2fe50a8da 100644 --- a/tests/inprocess/test_kernel.py +++ b/tests/inprocess/test_kernel.py @@ -119,3 +119,8 @@ async def test_do_execute(kc): kernel = InProcessKernel() await kernel.do_execute("a=1", True) assert kernel.shell.user_ns["a"] == 1 + +async def test_cell_meta_do_execute(): + kernel:InProcessKernel = InProcessKernel() + await kernel.do_execute("a=1", True, cell_meta={"testkey": "testvalue"}) + assert kernel.shell.user_ns["a"] == 1 From f549681a2322483df5e095eee9811fb5cb9e8ca7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 12 Nov 2025 05:20:59 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ipykernel/ipkernel.py | 4 +++- tests/inprocess/test_kernel.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ipykernel/ipkernel.py b/ipykernel/ipkernel.py index 0b45dc2e4..7b6f769d2 100644 --- a/ipykernel/ipkernel.py +++ b/ipykernel/ipkernel.py @@ -460,7 +460,9 @@ async def run_cell(*args, **kwargs): # runner isn't already running, # make synchronous call, # letting shell dispatch to loop runners - res = shell.run_cell(code, store_history=store_history, silent=silent, **do_execute_args) + res = shell.run_cell( + code, store_history=store_history, silent=silent, **do_execute_args + ) finally: self._restore_input() diff --git a/tests/inprocess/test_kernel.py b/tests/inprocess/test_kernel.py index 2fe50a8da..ad663313a 100644 --- a/tests/inprocess/test_kernel.py +++ b/tests/inprocess/test_kernel.py @@ -120,7 +120,8 @@ async def test_do_execute(kc): await kernel.do_execute("a=1", True) assert kernel.shell.user_ns["a"] == 1 + async def test_cell_meta_do_execute(): - kernel:InProcessKernel = InProcessKernel() + kernel: InProcessKernel = InProcessKernel() await kernel.do_execute("a=1", True, cell_meta={"testkey": "testvalue"}) assert kernel.shell.user_ns["a"] == 1