From 948972625d08345cdad177a2e94a2bbe6280960b Mon Sep 17 00:00:00 2001 From: essentiaMarco <131397104+essentiaMarco@users.noreply.github.com> Date: Sun, 15 Mar 2026 17:30:20 -0700 Subject: [PATCH] fix(cli): optional cli_main type for both with/without fastapi[standard] so pre-commit passes in CI Made-with: Cursor --- fastapi/cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fastapi/cli.py b/fastapi/cli.py index 2dd2febdb9..618953e66d 100644 --- a/fastapi/cli.py +++ b/fastapi/cli.py @@ -1,12 +1,15 @@ +from collections.abc import Callable + +cli_main: Callable[[], None] | None = None try: - from fastapi_cli.cli import main as cli_main # type: ignore[import-not-found] + from fastapi_cli.cli import main as cli_main except ImportError: # pragma: no cover - cli_main = None + pass def main() -> None: - if not cli_main: + if cli_main is None: message = 'To use the fastapi command, please install "fastapi[standard]":\n\n\tpip install "fastapi[standard]"\n' print(message) raise RuntimeError(message) # noqa: B904