Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix(cli): restore typechecking with Click 8.4 (#10738)

Shahmir Varqha535c156400a6
diff --git a/marimo/_cli/errors.py b/marimo/_cli/errors.py
index e8f7e35927..391ad5ae1d 100644
--- a/marimo/_cli/errors.py
+++ b/marimo/_cli/errors.py
@@ -1,7 +1,7 @@
# Copyright 2026 Marimo. All rights reserved.
from __future__ import annotations
-from typing import Any
+from typing import IO, Any
import click
@@ -12,15 +12,13 @@ from marimo._cli.print import bold, green, muted, red
class MarimoCLIError(click.ClickException):
"""Base class for marimo CLI errors."""
- def show(self, file: Any = None) -> None:
- if file is None:
- file = click.get_text_stream("stderr")
-
+ def show(self, file: IO[Any] | None = None) -> None:
ctx = getattr(self, "ctx", None)
color = ctx.color if ctx is not None else None
click.echo(
f"{red('Error', bold=True)}: {self.format_message()}",
file=file,
+ err=file is None,
color=color,
)
diff --git a/marimo/_cli/parser_ux.py b/marimo/_cli/parser_ux.py
index cdc63343e7..69ff289ca0 100644
--- a/marimo/_cli/parser_ux.py
+++ b/marimo/_cli/parser_ux.py
@@ -1,7 +1,7 @@
# Copyright 2026 Marimo. All rights reserved.
from __future__ import annotations
-from typing import Any
+from typing import IO, Any
import click
@@ -79,23 +79,25 @@ def _format_usage_error(error: click.UsageError) -> list[str]:
def show_compact_usage_error(
- error: click.UsageError, file: Any = None
+ error: click.UsageError, file: IO[Any] | None = None
) -> None:
"""Print compact parser errors without the full command help block."""
- if file is None:
- file = click.get_text_stream("stderr")
+ use_stderr = file is None
color = error.ctx.color if error.ctx is not None else None
for line in _format_usage_error(error):
- click.echo(line, file=file, color=color)
+ click.echo(line, file=file, err=use_stderr, color=color)
if error.ctx is not None:
- click.echo(file=file, color=color)
- click.echo(error.ctx.get_usage(), file=file, color=color)
- click.echo(file=file, color=color)
+ click.echo(file=file, err=use_stderr, color=color)
+ click.echo(
+ error.ctx.get_usage(), file=file, err=use_stderr, color=color
+ )
+ click.echo(file=file, err=use_stderr, color=color)
click.echo(
"For more information, try '--help'.",
file=file,
+ err=use_stderr,
color=color,
)