Skip to content

Commit e3002c6

Browse files
authored
Complete stubs for click-web (#13806)
1 parent bb1cbfa commit e3002c6

File tree

5 files changed

+76
-27
lines changed

5 files changed

+76
-27
lines changed

stubs/click-web/click_web/resources/__init__.pyi

Whitespace-only changes.

stubs/click-web/click_web/resources/cmd_exec.pyi

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
import logging
2+
from collections.abc import Generator
3+
from typing import ClassVar, Final
24

35
from flask import Response
46

57
from .input_fields import FieldId
68

79
logger: logging.Logger | None
810

9-
HTML_HEAD: str
10-
HTML_TAIL: str
11+
HTML_HEAD: Final[str]
12+
HTML_TAIL: Final[str]
1113

1214
class Executor:
13-
RAW_CMD_PATH: str
15+
RAW_CMD_PATH: ClassVar[str]
16+
returncode: int | None
1417

1518
def __init__(self) -> None: ...
1619
def exec(self, command_path: str) -> Response: ...
1720
def _exec_raw(self, command: list[str]) -> Response: ... # undocumented
1821
def _exec_html(self, command_path: str) -> Response: ... # undocumented
19-
def _run_script_and_generate_stream(self) -> None: ... # undocumented
22+
def _run_script_and_generate_stream(self) -> Generator[str]: ... # undocumented
2023
def _create_cmd_header(self, commands: list[CmdPart]) -> str: ... # undocumented
21-
def _create_result_footer(self) -> str: ... # undocumented
24+
def _create_result_footer(self) -> Generator[str]: ... # undocumented
2225

2326
def _get_download_link(field_info: FieldFileInfo) -> str: ... # undocumented
2427

@@ -30,6 +33,7 @@ class CommandLineRaw:
3033
def after_script_executed(self) -> None: ...
3134

3235
class CommandLineForm:
36+
command_line_bulder: FormToCommandLineBuilder
3337
def __init__(self, script_file_path: str, commands: list[str]) -> None: ...
3438
def append(self, part: str, secret: bool = False) -> None: ...
3539
def get_commandline(self, obfuscate: bool = False) -> list[str]: ...
@@ -49,6 +53,11 @@ class FormToCommandLineBuilder:
4953
def _process_option(self, field_info: FieldInfo) -> None: ...
5054

5155
class FieldInfo:
56+
param: FieldId
57+
key: str
58+
is_file: bool
59+
cmd_opt: str
60+
generate_download_link: bool
5261
@staticmethod
5362
def factory(key: str) -> FieldInfo: ...
5463
def __init__(self, param: FieldId) -> None: ...
@@ -58,13 +67,18 @@ class FieldInfo:
5867
def __eq__(self, other: object) -> bool: ...
5968

6069
class FieldFileInfo(FieldInfo):
70+
mode: str
71+
generate_download_link: bool
72+
link_name: str
73+
file_path: str
6174
def __init__(self, fimeta: FieldId) -> None: ...
6275
def before_script_execute(self) -> None: ...
6376
@classmethod
6477
def temp_dir(cls) -> str: ...
6578
def save(self) -> None: ...
6679

6780
class FieldOutFileInfo(FieldFileInfo):
81+
file_suffix: str
6882
def __init__(self, fimeta: FieldId) -> None: ...
6983
def save(self) -> None: ...
7084

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from collections import OrderedDict
12
from typing import Any
23

34
import click
45

56
def index() -> str: ...
6-
def _click_to_tree(ctx: click.Context, node: click.Command, ancestors: list[click.Command] | None = None) -> dict[str, Any]: ...
7+
def _click_to_tree(
8+
ctx: click.Context, node: click.Command, ancestors: list[click.Command] | None = None
9+
) -> OrderedDict[str, Any]: ...
Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
from typing import Any
1+
from typing import Any, ClassVar, Final
22

33
import click
4+
from click_web.web_click_types import EmailParamType, PasswordParamType, TextAreaParamType
45

56
class FieldId:
6-
SEPARATOR: str
7+
SEPARATOR: ClassVar[str]
8+
command_index: int
9+
param_index: int
10+
param_type: str
11+
click_type: str
12+
nargs: int
13+
form_type: str
14+
name: str
15+
key: str
716

817
def __init__(
918
self,
@@ -22,7 +31,11 @@ class FieldId:
2231
class NotSupported(ValueError): ...
2332

2433
class BaseInput:
25-
param_type_cls: type | None
34+
param_type_cls: type[click.types.ParamType] | None
35+
ctx: click.Context
36+
param: click.Parameter
37+
command_index: int
38+
param_index: int
2639
def __init__(self, ctx: click.Context, param: click.Parameter, command_index: int, param_index: int) -> None: ...
2740
def is_supported(self) -> bool: ...
2841
@property
@@ -32,18 +45,37 @@ class BaseInput:
3245
def _to_cmd_line_name(self, name: str) -> str: ...
3346
def _build_name(self, name: str): ...
3447

35-
class ChoiceInput(BaseInput): ...
36-
class FlagInput(BaseInput): ...
37-
class IntInput(BaseInput): ...
38-
class FloatInput(BaseInput): ...
39-
class FolderInput(BaseInput): ...
40-
class FileInput(BaseInput): ...
41-
class EmailInput(BaseInput): ...
42-
class PasswordInput(BaseInput): ...
43-
class TextAreaInput(BaseInput): ...
44-
class DefaultInput(BaseInput): ...
45-
46-
INPUT_TYPES: list[type]
47-
_DEFAULT_INPUT: list[type]
48+
class ChoiceInput(BaseInput):
49+
param_type_cls: type[click.Choice]
50+
51+
class FlagInput(BaseInput):
52+
param_type_cls: None
53+
54+
class IntInput(BaseInput):
55+
param_type_cls: type[click.types.IntParamType]
56+
57+
class FloatInput(BaseInput):
58+
param_type_cls: type[click.types.FloatParamType]
59+
60+
class FolderInput(BaseInput):
61+
param_type_cls: None
62+
63+
class FileInput(BaseInput):
64+
param_type_cls: None
65+
66+
class EmailInput(BaseInput):
67+
param_type_cls: type[EmailParamType]
68+
69+
class PasswordInput(BaseInput):
70+
param_type_cls: type[PasswordParamType]
71+
72+
class TextAreaInput(BaseInput):
73+
param_type_cls: type[TextAreaParamType]
74+
75+
class DefaultInput(BaseInput):
76+
param_type_cls: type[click.ParamType]
77+
78+
INPUT_TYPES: Final[list[type[BaseInput]]]
79+
_DEFAULT_INPUT: Final[list[type[DefaultInput]]]
4880

4981
def get_input_field(ctx: click.Context, param: click.Parameter, command_index, param_index) -> dict[str, Any]: ...

stubs/click-web/click_web/web_click_types.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import re
2-
import typing as t
2+
from typing import ClassVar
33

44
import click
55

66
class EmailParamType(click.ParamType):
7-
EMAIL_REGEX: re.Pattern[str]
8-
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
7+
EMAIL_REGEX: ClassVar[re.Pattern[str]]
8+
def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ...
99

1010
class PasswordParamType(click.ParamType):
11-
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
11+
def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ...
1212

1313
class TextAreaParamType(click.ParamType):
14-
def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ...
14+
def convert(self, value: str, param: click.Parameter | None, ctx: click.Context | None) -> str | None: ...
1515

1616
EMAIL_TYPE: EmailParamType
1717
PASSWORD_TYPE: PasswordParamType

0 commit comments

Comments
 (0)