Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand All @@ -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]
Expand All @@ -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(
Expand All @@ -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)
Expand All @@ -454,15 +460,9 @@ 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()

Expand Down
6 changes: 6 additions & 0 deletions tests/inprocess/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@ 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
Loading