From e3002c6f0d0752862688000843325e64812ac2b5 Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Fri, 11 Apr 2025 16:54:34 +0400 Subject: [PATCH] Complete stubs for `click-web` (#13806) --- .../click_web/resources/__init__.pyi | 0 .../click_web/resources/cmd_exec.pyi | 24 +++++-- stubs/click-web/click_web/resources/index.pyi | 5 +- .../click_web/resources/input_fields.pyi | 62 ++++++++++++++----- stubs/click-web/click_web/web_click_types.pyi | 10 +-- 5 files changed, 75 insertions(+), 26 deletions(-) create mode 100644 stubs/click-web/click_web/resources/__init__.pyi diff --git a/stubs/click-web/click_web/resources/__init__.pyi b/stubs/click-web/click_web/resources/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/click-web/click_web/resources/cmd_exec.pyi b/stubs/click-web/click_web/resources/cmd_exec.pyi index 1c616c678..b1121b450 100644 --- a/stubs/click-web/click_web/resources/cmd_exec.pyi +++ b/stubs/click-web/click_web/resources/cmd_exec.pyi @@ -1,4 +1,6 @@ import logging +from collections.abc import Generator +from typing import ClassVar, Final from flask import Response @@ -6,19 +8,20 @@ from .input_fields import FieldId logger: logging.Logger | None -HTML_HEAD: str -HTML_TAIL: str +HTML_HEAD: Final[str] +HTML_TAIL: Final[str] class Executor: - RAW_CMD_PATH: str + RAW_CMD_PATH: ClassVar[str] + returncode: int | None def __init__(self) -> None: ... def exec(self, command_path: str) -> Response: ... def _exec_raw(self, command: list[str]) -> Response: ... # undocumented def _exec_html(self, command_path: str) -> Response: ... # undocumented - def _run_script_and_generate_stream(self) -> None: ... # undocumented + def _run_script_and_generate_stream(self) -> Generator[str]: ... # undocumented def _create_cmd_header(self, commands: list[CmdPart]) -> str: ... # undocumented - def _create_result_footer(self) -> str: ... # undocumented + def _create_result_footer(self) -> Generator[str]: ... # undocumented def _get_download_link(field_info: FieldFileInfo) -> str: ... # undocumented @@ -30,6 +33,7 @@ class CommandLineRaw: def after_script_executed(self) -> None: ... class CommandLineForm: + command_line_bulder: FormToCommandLineBuilder def __init__(self, script_file_path: str, commands: list[str]) -> None: ... def append(self, part: str, secret: bool = False) -> None: ... def get_commandline(self, obfuscate: bool = False) -> list[str]: ... @@ -49,6 +53,11 @@ class FormToCommandLineBuilder: def _process_option(self, field_info: FieldInfo) -> None: ... class FieldInfo: + param: FieldId + key: str + is_file: bool + cmd_opt: str + generate_download_link: bool @staticmethod def factory(key: str) -> FieldInfo: ... def __init__(self, param: FieldId) -> None: ... @@ -58,6 +67,10 @@ class FieldInfo: def __eq__(self, other: object) -> bool: ... class FieldFileInfo(FieldInfo): + mode: str + generate_download_link: bool + link_name: str + file_path: str def __init__(self, fimeta: FieldId) -> None: ... def before_script_execute(self) -> None: ... @classmethod @@ -65,6 +78,7 @@ class FieldFileInfo(FieldInfo): def save(self) -> None: ... class FieldOutFileInfo(FieldFileInfo): + file_suffix: str def __init__(self, fimeta: FieldId) -> None: ... def save(self) -> None: ... diff --git a/stubs/click-web/click_web/resources/index.pyi b/stubs/click-web/click_web/resources/index.pyi index c932a5a7e..c0f3aebbb 100644 --- a/stubs/click-web/click_web/resources/index.pyi +++ b/stubs/click-web/click_web/resources/index.pyi @@ -1,6 +1,9 @@ +from collections import OrderedDict from typing import Any import click def index() -> str: ... -def _click_to_tree(ctx: click.Context, node: click.Command, ancestors: list[click.Command] | None = None) -> dict[str, Any]: ... +def _click_to_tree( + ctx: click.Context, node: click.Command, ancestors: list[click.Command] | None = None +) -> OrderedDict[str, Any]: ... diff --git a/stubs/click-web/click_web/resources/input_fields.pyi b/stubs/click-web/click_web/resources/input_fields.pyi index 65b301898..92e2289e9 100644 --- a/stubs/click-web/click_web/resources/input_fields.pyi +++ b/stubs/click-web/click_web/resources/input_fields.pyi @@ -1,9 +1,18 @@ -from typing import Any +from typing import Any, ClassVar, Final import click +from click_web.web_click_types import EmailParamType, PasswordParamType, TextAreaParamType class FieldId: - SEPARATOR: str + SEPARATOR: ClassVar[str] + command_index: int + param_index: int + param_type: str + click_type: str + nargs: int + form_type: str + name: str + key: str def __init__( self, @@ -22,7 +31,11 @@ class FieldId: class NotSupported(ValueError): ... class BaseInput: - param_type_cls: type | None + param_type_cls: type[click.types.ParamType] | None + ctx: click.Context + param: click.Parameter + command_index: int + param_index: int def __init__(self, ctx: click.Context, param: click.Parameter, command_index: int, param_index: int) -> None: ... def is_supported(self) -> bool: ... @property @@ -32,18 +45,37 @@ class BaseInput: def _to_cmd_line_name(self, name: str) -> str: ... def _build_name(self, name: str): ... -class ChoiceInput(BaseInput): ... -class FlagInput(BaseInput): ... -class IntInput(BaseInput): ... -class FloatInput(BaseInput): ... -class FolderInput(BaseInput): ... -class FileInput(BaseInput): ... -class EmailInput(BaseInput): ... -class PasswordInput(BaseInput): ... -class TextAreaInput(BaseInput): ... -class DefaultInput(BaseInput): ... +class ChoiceInput(BaseInput): + param_type_cls: type[click.Choice] -INPUT_TYPES: list[type] -_DEFAULT_INPUT: list[type] +class FlagInput(BaseInput): + param_type_cls: None + +class IntInput(BaseInput): + param_type_cls: type[click.types.IntParamType] + +class FloatInput(BaseInput): + param_type_cls: type[click.types.FloatParamType] + +class FolderInput(BaseInput): + param_type_cls: None + +class FileInput(BaseInput): + param_type_cls: None + +class EmailInput(BaseInput): + param_type_cls: type[EmailParamType] + +class PasswordInput(BaseInput): + param_type_cls: type[PasswordParamType] + +class TextAreaInput(BaseInput): + param_type_cls: type[TextAreaParamType] + +class DefaultInput(BaseInput): + param_type_cls: type[click.ParamType] + +INPUT_TYPES: Final[list[type[BaseInput]]] +_DEFAULT_INPUT: Final[list[type[DefaultInput]]] def get_input_field(ctx: click.Context, param: click.Parameter, command_index, param_index) -> dict[str, Any]: ... diff --git a/stubs/click-web/click_web/web_click_types.pyi b/stubs/click-web/click_web/web_click_types.pyi index 1546f7e7d..b0e9e378f 100644 --- a/stubs/click-web/click_web/web_click_types.pyi +++ b/stubs/click-web/click_web/web_click_types.pyi @@ -1,17 +1,17 @@ import re -import typing as t +from typing import ClassVar import click class EmailParamType(click.ParamType): - EMAIL_REGEX: re.Pattern[str] - def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + EMAIL_REGEX: ClassVar[re.Pattern[str]] + def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ... class PasswordParamType(click.ParamType): - def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ... class TextAreaParamType(click.ParamType): - def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ... EMAIL_TYPE: EmailParamType PASSWORD_TYPE: PasswordParamType