From 673cecca797976bb595d77a006dcd3ce572c5907 Mon Sep 17 00:00:00 2001 From: Teis Johansen <14347485+teis-j@users.noreply.github.com> Date: Wed, 20 Aug 2025 11:38:25 +0200 Subject: [PATCH] [click-shell] Add stubs for click-shell (#14578) --- stubs/click-shell/METADATA.toml | 3 ++ stubs/click-shell/click_shell/__init__.pyi | 7 ++++ stubs/click-shell/click_shell/_cmd.pyi | 28 ++++++++++++++++ stubs/click-shell/click_shell/_compat.pyi | 10 ++++++ stubs/click-shell/click_shell/core.pyi | 35 ++++++++++++++++++++ stubs/click-shell/click_shell/decorators.pyi | 8 +++++ 6 files changed, 91 insertions(+) create mode 100644 stubs/click-shell/METADATA.toml create mode 100644 stubs/click-shell/click_shell/__init__.pyi create mode 100644 stubs/click-shell/click_shell/_cmd.pyi create mode 100644 stubs/click-shell/click_shell/_compat.pyi create mode 100644 stubs/click-shell/click_shell/core.pyi create mode 100644 stubs/click-shell/click_shell/decorators.pyi diff --git a/stubs/click-shell/METADATA.toml b/stubs/click-shell/METADATA.toml new file mode 100644 index 000000000..630e551b1 --- /dev/null +++ b/stubs/click-shell/METADATA.toml @@ -0,0 +1,3 @@ +version = "2.1" +upstream_repository = "https://github.com/clarkperkins/click-shell" +requires = ["click>=8.0.0"] diff --git a/stubs/click-shell/click_shell/__init__.pyi b/stubs/click-shell/click_shell/__init__.pyi new file mode 100644 index 000000000..38ef48feb --- /dev/null +++ b/stubs/click-shell/click_shell/__init__.pyi @@ -0,0 +1,7 @@ +from typing import Final + +from .core import Shell as Shell, make_click_shell as make_click_shell +from .decorators import shell as shell + +__all__ = ["make_click_shell", "shell", "Shell", "__version__"] +__version__: Final[str] diff --git a/stubs/click-shell/click_shell/_cmd.pyi b/stubs/click-shell/click_shell/_cmd.pyi new file mode 100644 index 000000000..c6848e489 --- /dev/null +++ b/stubs/click-shell/click_shell/_cmd.pyi @@ -0,0 +1,28 @@ +from cmd import Cmd +from collections.abc import Callable +from typing import Any, ClassVar, TextIO + +import click + +class ClickCmd(Cmd): + nocommand: ClassVar[str] + def __init__( + self, + ctx: click.Context | None = None, + on_finished: Callable[[click.Context], None] | None = None, + hist_file: str | None = None, + completekey: str = "tab", + stdin: TextIO | None = None, + stdout: TextIO | None = None, + ) -> None: ... + def preloop(self) -> None: ... + def postloop(self) -> None: ... + def cmdloop(self, intro: str | None = None) -> None: ... + def get_prompt(self) -> str | None: ... + def emptyline(self) -> bool: ... + def default(self, line: str) -> None: ... + def get_names(self) -> list[str]: ... + def do_help(self, arg: str) -> None: ... + def do_quit(self, arg: str) -> bool: ... + def do_exit(self, arg: str) -> bool: ... + def print_topics(self, header: Any, cmds: list[str] | None, cmdlen: int, maxcol: int) -> None: ... diff --git a/stubs/click-shell/click_shell/_compat.pyi b/stubs/click-shell/click_shell/_compat.pyi new file mode 100644 index 000000000..c383de4ff --- /dev/null +++ b/stubs/click-shell/click_shell/_compat.pyi @@ -0,0 +1,10 @@ +import types +from collections.abc import Callable +from typing import Any, Final + +import click + +PY2: Final = False + +def get_method_type(func: Callable[..., Any], obj: object) -> types.MethodType: ... +def get_choices(cli: click.Command, prog_name: str, args: list[str], incomplete: str) -> list[str]: ... diff --git a/stubs/click-shell/click_shell/core.pyi b/stubs/click-shell/click_shell/core.pyi new file mode 100644 index 000000000..673c0c694 --- /dev/null +++ b/stubs/click-shell/click_shell/core.pyi @@ -0,0 +1,35 @@ +from collections.abc import Callable +from logging import Logger +from typing import Any + +import click + +from ._cmd import ClickCmd + +logger: Logger + +def get_invoke(command: click.Command) -> Callable[[ClickCmd, str], bool]: ... +def get_help(command: click.Command) -> Callable[[ClickCmd], None]: ... +def get_complete(command: click.Command) -> Callable[[ClickCmd, str, str, int, int], list[str]]: ... + +class ClickShell(ClickCmd): + def add_command(self, cmd: click.Command, name: str) -> None: ... + +def make_click_shell( + ctx: click.Context, + prompt: str | Callable[[], str] | Callable[[click.Context, str], str] | None = None, + intro: str | None = None, + hist_file: str | None = None, +) -> ClickShell: ... + +class Shell(click.Group): + def __init__( + self, + prompt: str | Callable[[], str] | Callable[[click.Context, str], str] | None = None, + intro: str | None = None, + hist_file: str | None = None, + on_finished: Callable[[click.Context], None] | None = None, + **attrs: Any, + ) -> None: ... + def add_command(self, cmd: click.Command, name: str | None = None) -> None: ... + def invoke(self, ctx: click.Context) -> Any: ... diff --git a/stubs/click-shell/click_shell/decorators.pyi b/stubs/click-shell/click_shell/decorators.pyi new file mode 100644 index 000000000..ce72f74fb --- /dev/null +++ b/stubs/click-shell/click_shell/decorators.pyi @@ -0,0 +1,8 @@ +from collections.abc import Callable +from typing import Any + +from click.decorators import _AnyCallable + +from .core import Shell + +def shell(name: str | None = None, **attrs: Any) -> Callable[[_AnyCallable], Shell]: ...