Skip to content

Commit fb45b1a

Browse files
committed
fix: comment cleanup
1 parent 875957d commit fb45b1a

9 files changed

Lines changed: 77 additions & 118 deletions

File tree

marimo/_ast/cell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ def _is_coroutine(self) -> bool:
483483
assert self._app is not None
484484
from marimo._runtime.runner import by_kwargs
485485

486-
# ``graph`` triggers _maybe_initialize on the underlying App.
486+
# Currently expensive since `graph` triggers _maybe_initialize on the
487+
# underlying App.
487488
self._is_coro_cached: bool = by_kwargs.is_coroutine(
488489
self._app.graph, self._cell.cell_id
489490
)

marimo/_runtime/app/script_runner.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,22 +153,14 @@ def _handle_run_result(
153153
result: RunResult,
154154
outputs: dict[CellId_t, Any],
155155
) -> None:
156-
"""Classify the Evaluator's RunResult; record output, cancel, or raise.
157-
158-
Aligns MarimoStopError handling with the kernel classifier: the
159-
stop's output is recorded for the cell and descendants are
160-
cancelled, instead of silently swallowing both.
161-
"""
156+
"""Classify the Evaluator's RunResult; record output/cancel/raise."""
162157
exc = result.exception
163158
if exc is None:
164159
outputs[cid] = result.output
165160
return
166161
if not isinstance(exc, BaseException):
167-
# An Error-shape payload (e.g. ``MarimoStrictExecutionError``)
168-
# from a lifecycle ``Skip(result=...)``. Script mode runs with
169-
# no lifecycles today, so this is unreachable in practice;
170-
# treat defensively by recording the output and cancelling
171-
# descendants.
162+
# Defensive check descendants, since all exceptions are expected to
163+
# be wrapper..
172164
outputs[cid] = result.output
173165
self._scheduler.cancel(cid)
174166
return

marimo/_runtime/executor/evaluator.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async def evaluate(
4949
result: RunResult = RunResult(output=None, exception=body_exc)
5050
elif skip is not None:
5151
# Lifecycle short-circuited — pass its full RunResult through
52-
# so ``accumulated_output`` and any other field survive.
52+
# so `accumulated_output` and any other field survive.
5353
result = (
5454
skip.result
5555
if skip.result is not None
@@ -67,7 +67,7 @@ async def evaluate(
6767
def evaluate_sync(
6868
self, cell: CellImpl, glbls: MutableGlobals
6969
) -> RunResult:
70-
"""Sync mirror of ``evaluate`` — for callers without an event loop."""
70+
"""Sync mirror of `evaluate` — for callers without an event loop."""
7171
completed, skip, body_exc = self._setup_chain(cell, glbls)
7272

7373
if body_exc is not None:
@@ -90,12 +90,7 @@ def evaluate_sync(
9090
async def evaluate_interruptible(
9191
self, cell: CellImpl, glbls: MutableGlobals
9292
) -> RunResult:
93-
"""Await ``evaluate`` with SIGINT capture for coroutine cells.
94-
95-
SIGINT during an awaited coroutine raises in the event loop, not
96-
in the user's coroutine. Wrap the future so SIGINT cancels it.
97-
Sync cells and non-main-thread callers just await ``evaluate``.
98-
"""
93+
"""Await `evaluate` with SIGINT capture for coroutine cells."""
9994
if not cell.is_coroutine():
10095
return await self.evaluate(cell, glbls)
10196
future = asyncio.ensure_future(self.evaluate(cell, glbls))
@@ -190,12 +185,7 @@ def resolve_executor() -> Executor:
190185
# https://github.com/ipython/ipykernel/blob/eddd3e666a82ebec287168b0da7cfa03639a3772/ipykernel/ipkernel.py#L312
191186
@contextlib.contextmanager
192187
def _cancel_on_sigint(future: asyncio.Future[Any]) -> Iterator[None]:
193-
"""Cancel ``future`` if a SIGINT arrives during the ``with`` block.
194-
195-
SIGINT raises in the event loop when running async code, but we want
196-
it to halt the coroutine. Ideally it would raise ``KeyboardInterrupt``,
197-
but this turns it into a ``CancelledError``.
198-
"""
188+
"""Cancel `future` if a SIGINT arrives during evaluation."""
199189
sigint_future: asyncio.Future[int] = asyncio.Future()
200190

201191
def cancel_unless_done(f: asyncio.Future[Any], _: Any) -> None:
@@ -211,10 +201,10 @@ def cancel_unless_done(f: asyncio.Future[Any], _: Any) -> None:
211201
)
212202

213203
# Capture the previously-installed SIGINT handler *before* we install
214-
# ours so ``handle_sigint`` can invoke it for its side effects
204+
# ours so `handle_sigint` can invoke it for its side effects
215205
# (kernel broadcast, duckdb interrupt). For async cells the actual
216206
# halt comes from cancelling the future, not from a raised
217-
# ``MarimoInterrupt`` — so we swallow that here.
207+
# `MarimoInterrupt` — so we swallow that here.
218208
prior_sigint = signal.getsignal(signal.SIGINT)
219209

220210
def handle_sigint(signum: int, frame: Any) -> None:

marimo/_runtime/executor/executor.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515

1616

1717
def _strip_frame(e: BaseException, count: int = 1) -> None:
18-
"""Drop the top ``count`` frames from ``e.__traceback__``.
18+
"""Drop the top `count` frames from `e.__traceback__`.
1919
20-
Used by executors to elide their own frames so user-facing
21-
tracebacks start at user code. Stops early if the traceback runs
22-
out — never strips the last frame, so we don't lose the only
23-
frame we have.
20+
Stops early if the traceback runs out — never strips the last
21+
frame, so we don't lose the only frame we have.
2422
"""
2523
tb = e.__traceback__
2624
for _ in range(count):
@@ -58,9 +56,7 @@ def execute_cell(self, cell: CellImpl, glbls: MutableGlobals) -> Any:
5856
exec(cell.body, glbls)
5957
return eval(cell.last_expr, glbls)
6058
except asyncio.CancelledError:
61-
# Cancellation is control flow, not user error — let the
62-
# caller see the bare exception so the runner's interrupt
63-
# path fires.
59+
# Cancellation is control flow, not user error — surface bare.
6460
raise
6561
except BaseException as e:
6662
# Strip our own frame so user-facing tracebacks start at user code.

marimo/_runtime/runner/by_kwargs.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright 2026 Marimo. All rights reserved.
2-
"""Run individual cells in a graph with caller-provided ref substitution.
2+
"""Lightweight runner functions for use in direct cell evaluation or testing.
33
4-
Backs the ``Cell.run(**kwargs)`` public API. Walks the cell's ancestor
5-
closure (minus any ancestor whose defs the caller substituted via
6-
kwargs), runs them with a fresh globals dict, then runs the target cell.
4+
Walks the cell's ancestor closure (minus any ancestor whose defs the
5+
caller substituted via kwargs), runs them with a fresh globals dict,
6+
then runs the target cell.
77
"""
88

99
from __future__ import annotations
@@ -76,17 +76,12 @@ def _get_ancestors(
7676

7777

7878
def _classify(result: RunResult) -> MarimoStopError | None:
79-
"""Inspect a RunResult; raise on real errors, return the stop on mo.stop.
80-
81-
``MarimoStopError`` is control flow, not a user-facing error — by_kwargs
82-
halts cleanly and surfaces the carried output in place of raising. Any
83-
other exception is the user's and propagates.
84-
"""
79+
"""Inspect a RunResult; raise on real errors, return the stop on mo.stop."""
8580
exc = result.exception
8681
if exc is None:
8782
return None
8883
if isinstance(exc, MarimoStopError):
89-
# Defensive: any caller bypassing ``MarimoRuntimeException``
84+
# Defensive: any caller bypassing `MarimoRuntimeException`
9085
# wrapping (e.g. a custom Executor that raises directly) still
9186
# gets stop-control-flow handling.
9287
return exc
@@ -106,10 +101,7 @@ def is_coroutine(
106101
) -> bool:
107102
"""True if the cell or any of its unsubstituted ancestors is async.
108103
109-
Pass ``kwargs`` if you want substitutions taken into account — an
110-
ancestor whose def is provided by the caller is omitted from the
111-
ancestor closure, so a graph that *would* be async without the
112-
substitution may be sync with it.
104+
NB. Currently expensive due to calls on graph.
113105
"""
114106
return graph.cells[cell_id].is_coroutine() or any(
115107
graph.cells[cid].is_coroutine()
@@ -160,7 +152,7 @@ def run_cell_sync(
160152
Substitutes kwargs as refs for the cell, omitting ancestors whose
161153
refs are substituted.
162154
163-
Raises ``RuntimeError`` if the cell or any of its unsubstituted
155+
Raises `RuntimeError` if the cell or any of its unsubstituted
164156
ancestors are coroutine functions.
165157
"""
166158
from marimo._runtime.dataflow import topological_sort

marimo/_types/globals.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Copyright 2026 Marimo. All rights reserved.
22
"""Type aliases for cell globals dicts.
33
4-
``MutableGlobals`` is the concrete ``dict`` passed through ``exec`` /
5-
``eval``; ``Globals`` is the read-only view for consumers that only
4+
`MutableGlobals` is the concrete `dict` passed through `exec` /
5+
`eval`; `Globals` is the read-only view for consumers that only
66
inspect the dict (e.g. collecting a cell's defs after execution).
77
"""
88

tests/_runtime/runner/test_cell_runner.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ async def test_runner_dispatches_to_registered_plugin_executor(
286286
exec_req: ExecReqProvider,
287287
monkeypatch: pytest.MonkeyPatch,
288288
) -> None:
289-
"""A factory registered against ``marimo.cell.executor`` is the one
290-
the kernel ``Runner`` dispatches through — proves the plugin flow
291-
works end-to-end, not just the registry in isolation."""
289+
"""A factory registered against `marimo.cell.executor` is the one
290+
the kernel `Runner` dispatches through."""
292291
from typing import Any
293292

294293
from marimo._runtime.executor.evaluator import _EXECUTOR_REGISTRY
@@ -319,8 +318,8 @@ def factory() -> _SentinelExecutor:
319318
k = execution_kernel
320319
await k.run([er := exec_req.get("'hello'; 123")])
321320

322-
# Fully isolate the registry: replace both ``_plugins`` and
323-
# ``names`` so installed third-party entry points can't shadow the
321+
# Fully isolate the registry: replace both `_plugins` and
322+
# `names` so installed third-party entry points can't shadow the
324323
# sentinel. monkeypatch restores both on teardown.
325324
monkeypatch.setattr(_EXECUTOR_REGISTRY, "_plugins", {"sentinel": factory})
326325
monkeypatch.setattr(_EXECUTOR_REGISTRY, "names", lambda: ["sentinel"])
@@ -344,9 +343,9 @@ def factory() -> _SentinelExecutor:
344343
async def test_runner_interrupted_flag_flips_on_sync_marimo_interrupt(
345344
execution_kernel: Kernel, exec_req: ExecReqProvider
346345
) -> None:
347-
"""Sync cell body raising ``MarimoInterrupt`` (== ``KeyboardInterrupt``)
348-
surfaces as a bare ``MarimoInterrupt`` in the run result and flips
349-
``runner.interrupted``. Covers ``cell_runner.py:441-442``."""
346+
"""Sync cell body raising `MarimoInterrupt` (== `KeyboardInterrupt`)
347+
surfaces as a bare `MarimoInterrupt` in the run result and flips
348+
`runner.interrupted`."""
350349
k = execution_kernel
351350
await k.run([er := exec_req.get("raise KeyboardInterrupt")])
352351

@@ -368,19 +367,16 @@ async def test_runner_interrupted_flag_flips_on_async_cell_cancellation(
368367
exec_req: ExecReqProvider,
369368
monkeypatch: pytest.MonkeyPatch,
370369
) -> None:
371-
"""An async cell cancelled mid-await flips ``runner.interrupted``.
372-
373-
After the production fix, ``CancelledError`` propagates unwrapped
374-
from ``DefaultExecutor`` and arrives in the ``RunResult.exception``
375-
as a bare ``asyncio.CancelledError``. ``_finalize_run_result``'s
376-
bare-``CancelledError`` branch converts it to ``MarimoInterrupt``,
377-
which ``run()`` recognises to flip the flag.
378-
379-
We simulate the post-fix evaluator output directly (a bare
380-
``CancelledError`` in the ``RunResult``) so this test is independent
381-
of the executor's coroutine compilation; the executor-level
382-
propagation is covered by
383-
``test_executor_async_cancellation_propagates_unwrapped``.
370+
"""An async cell cancelled mid-await flips `runner.interrupted`.
371+
372+
A bare `asyncio.CancelledError` arriving in `RunResult.exception` is
373+
converted to `MarimoInterrupt` by the bare-`CancelledError` branch
374+
of `_finalize_run_result`, which `run()` recognises to flip the
375+
flag.
376+
377+
Simulates the evaluator output directly (a bare `CancelledError` in
378+
the `RunResult`) so this test is independent of the executor's
379+
coroutine compilation.
384380
"""
385381
import asyncio
386382

0 commit comments

Comments
 (0)