Debian Codegraph @

cloup/_params.pyi

raw
1 """
2 Types for parameter decorators are in this stub for convenience of implementation.
3 """
4 from typing import Any, Callable, List, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union
5
6 import click
7 from click.shell_completion import CompletionItem
8
9 from cloup import OptionGroup
10
11 F = TypeVar('F', bound=Callable[..., Any])
12 P = TypeVar('P', bound=click.Parameter)
13
14 class _ParamType(Protocol):
15 # Once Click 8.3 support is dropped, this can be replaced with
16 # click.ParamType[Any].
17 @property
18 def name(self) -> Optional[str]:
19 ...
20
21 def convert(
22 self,
23 value: Any,
24 param: Optional[click.Parameter],
25 ctx: Optional[click.Context],
26 ) -> Any:
27 ...
28
29
30 SimpleParamTypeLike = Union[_ParamType, Type[float], Type[int], Type[str]]
31 ParamTypeLike = Union[SimpleParamTypeLike, Tuple[SimpleParamTypeLike, ...]]
32 ParamDefault = Union[Any, Callable[[], Any]]
33 ParamCallback = Callable[[click.Context, P, Any], Any]
34 ShellCompleteArg = Callable[
35 [click.Context, P, str],
36 Union[List[CompletionItem], List[str]],
37 ]
38
39
40 def make_arg_metavar(arg: click.Argument, ctx: click.Context) -> str:
41 ...
42
43
44 class Argument(click.Argument):
45 def __init__(self, *args: Any, help: Optional[str] = None, **attrs: Any):
46 ...
47
48 def get_help_record(self, ctx: click.Context) -> Tuple[str, str]:
49 ...
50
51
52 class Option(click.Option):
53 def __init__(self, *args: Any, group: Optional[OptionGroup] = None, **attrs: Any):
54 ...
55
56
57 def argument(
58 *param_decls: str,
59 cls: Optional[Type[Argument]] = None,
60 help: Optional[str] = None,
61 type: Optional[ParamTypeLike] = None,
62 required: Optional[bool] = None,
63 default: Optional[ParamDefault] = None,
64 callback: Optional[ParamCallback[click.Argument]] = None,
65 nargs: Optional[int] = None,
66 metavar: Optional[str] = None,
67 expose_value: bool = True,
68 envvar: Optional[Union[str, Sequence[str]]] = None,
69 shell_complete: Optional[ShellCompleteArg[click.Argument]] = None,
70 **kwargs: Any,
71 ) -> Callable[[F], F]: ...
72
73
74 def option(
75 *param_decls: str,
76 cls: Optional[Type[click.Option]] = None,
77 # Commonly used
78 metavar: Optional[str] = None,
79 type: Optional[ParamTypeLike] = None,
80 is_flag: Optional[bool] = None,
81 default: Optional[ParamDefault] = None,
82 required: Optional[bool] = None,
83 help: Optional[str] = None,
84 # Processing
85 callback: Optional[ParamCallback[click.Option]] = None,
86 is_eager: bool = False,
87 # Help text tuning
88 show_choices: bool = True,
89 show_default: bool = False,
90 show_envvar: bool = False,
91 # Flag options
92 flag_value: Optional[Any] = None,
93 count: bool = False,
94 # Multiple values
95 nargs: Optional[int] = None,
96 multiple: bool = False,
97 # Prompt
98 prompt: Union[bool, str] = False,
99 confirmation_prompt: Union[bool, str] = False,
100 prompt_required: bool = True,
101 hide_input: bool = False,
102 # Environment
103 allow_from_autoenv: bool = True,
104 envvar: Optional[Union[str, Sequence[str]]] = None,
105 # Hiding
106 hidden: bool = False,
107 expose_value: bool = True,
108 # Others
109 group: Optional[OptionGroup] = None,
110 shell_complete: Optional[ShellCompleteArg[click.Option]] = None,
111 **kwargs: Any
112 ) -> Callable[[F], F]: ...