Coverage for typer / params.py: 100%
7 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-02-09 12:36 +0000
1from typing import TYPE_CHECKING, Any, Callable, Optional, Union, overload 1abfcdgeh
3import click 1abfcdgeh
5from .models import ArgumentInfo, OptionInfo 1abfcdgeh
7if TYPE_CHECKING: # pragma: no cover 1abfcdgeh
8 import click.shell_completion
11# Overload for Option created with custom type 'parser'
12@overload 1abfcdgeh
13def Option( 1abfcdgeh
14 # Parameter
15 default: Optional[Any] = ..., 1abcde
16 *param_decls: str, 1abcde
17 callback: Optional[Callable[..., Any]] = None, 1abfcdgeh
18 metavar: Optional[str] = None, 1abfcdgeh
19 expose_value: bool = True, 1abfcdgeh
20 is_eager: bool = False, 1abfcdgeh
21 envvar: Optional[Union[str, list[str]]] = None, 1abfcdgeh
22 # Note that shell_complete is not fully supported and will be removed in future versions
23 # TODO: Remove shell_complete in a future version (after 0.16.0)
24 shell_complete: Optional[ 1abcde
25 Callable[ 1abcde
26 [click.Context, click.Parameter, str], 1abcde
27 Union[list["click.shell_completion.CompletionItem"], list[str]], 1abcde
28 ]
29 ] = None, 1abfcdgeh
30 autocompletion: Optional[Callable[..., Any]] = None, 1abfcdgeh
31 default_factory: Optional[Callable[[], Any]] = None, 1abfcdgeh
32 # Custom type
33 parser: Optional[Callable[[str], Any]] = None, 1abfcdgeh
34 # Option
35 show_default: Union[bool, str] = True, 1abfcdgeh
36 prompt: Union[bool, str] = False, 1abfcdgeh
37 confirmation_prompt: bool = False, 1abfcdgeh
38 prompt_required: bool = True, 1abfcdgeh
39 hide_input: bool = False, 1abfcdgeh
40 # TODO: remove is_flag and flag_value in a future release
41 is_flag: Optional[bool] = None, 1abfcdgeh
42 flag_value: Optional[Any] = None, 1abfcdgeh
43 count: bool = False, 1abfcdgeh
44 allow_from_autoenv: bool = True, 1abfcdgeh
45 help: Optional[str] = None, 1abfcdgeh
46 hidden: bool = False, 1abfcdgeh
47 show_choices: bool = True, 1abfcdgeh
48 show_envvar: bool = True, 1abfcdgeh
49 # Choice
50 case_sensitive: bool = True, 1abfcdgeh
51 # Numbers
52 min: Optional[Union[int, float]] = None, 1abfcdgeh
53 max: Optional[Union[int, float]] = None, 1abfcdgeh
54 clamp: bool = False, 1abfcdgeh
55 # DateTime
56 formats: Optional[list[str]] = None, 1abfcdgeh
57 # File
58 mode: Optional[str] = None, 1abfcdgeh
59 encoding: Optional[str] = None, 1abfcdgeh
60 errors: Optional[str] = "strict", 1abfcdgeh
61 lazy: Optional[bool] = None, 1abfcdgeh
62 atomic: bool = False, 1abfcdgeh
63 # Path
64 exists: bool = False, 1abfcdgeh
65 file_okay: bool = True, 1abfcdgeh
66 dir_okay: bool = True, 1abfcdgeh
67 writable: bool = False, 1abfcdgeh
68 readable: bool = True, 1abfcdgeh
69 resolve_path: bool = False, 1abfcdgeh
70 allow_dash: bool = False, 1abfcdgeh
71 path_type: Union[None, type[str], type[bytes]] = None, 1abfcdgeh
72 # Rich settings
73 rich_help_panel: Union[str, None] = None, 1abfcdgeh
74) -> Any: ... 1abcde
77# Overload for Option created with custom type 'click_type'
78@overload 1abfcdgeh
79def Option( 1abfcdgeh
80 # Parameter
81 default: Optional[Any] = ..., 1abcde
82 *param_decls: str, 1abcde
83 callback: Optional[Callable[..., Any]] = None, 1abfcdgeh
84 metavar: Optional[str] = None, 1abfcdgeh
85 expose_value: bool = True, 1abfcdgeh
86 is_eager: bool = False, 1abfcdgeh
87 envvar: Optional[Union[str, list[str]]] = None, 1abfcdgeh
88 # Note that shell_complete is not fully supported and will be removed in future versions
89 # TODO: Remove shell_complete in a future version (after 0.16.0)
90 shell_complete: Optional[ 1abcde
91 Callable[ 1abcde
92 [click.Context, click.Parameter, str], 1abcde
93 Union[list["click.shell_completion.CompletionItem"], list[str]], 1abcde
94 ]
95 ] = None, 1abfcdgeh
96 autocompletion: Optional[Callable[..., Any]] = None, 1abfcdgeh
97 default_factory: Optional[Callable[[], Any]] = None, 1abfcdgeh
98 # Custom type
99 click_type: Optional[click.ParamType] = None, 1abfcdgeh
100 # Option
101 show_default: Union[bool, str] = True, 1abfcdgeh
102 prompt: Union[bool, str] = False, 1abfcdgeh
103 confirmation_prompt: bool = False, 1abfcdgeh
104 prompt_required: bool = True, 1abfcdgeh
105 hide_input: bool = False, 1abfcdgeh
106 # TODO: remove is_flag and flag_value in a future release
107 is_flag: Optional[bool] = None, 1abfcdgeh
108 flag_value: Optional[Any] = None, 1abfcdgeh
109 count: bool = False, 1abfcdgeh
110 allow_from_autoenv: bool = True, 1abfcdgeh
111 help: Optional[str] = None, 1abfcdgeh
112 hidden: bool = False, 1abfcdgeh
113 show_choices: bool = True, 1abfcdgeh
114 show_envvar: bool = True, 1abfcdgeh
115 # Choice
116 case_sensitive: bool = True, 1abfcdgeh
117 # Numbers
118 min: Optional[Union[int, float]] = None, 1abfcdgeh
119 max: Optional[Union[int, float]] = None, 1abfcdgeh
120 clamp: bool = False, 1abfcdgeh
121 # DateTime
122 formats: Optional[list[str]] = None, 1abfcdgeh
123 # File
124 mode: Optional[str] = None, 1abfcdgeh
125 encoding: Optional[str] = None, 1abfcdgeh
126 errors: Optional[str] = "strict", 1abfcdgeh
127 lazy: Optional[bool] = None, 1abfcdgeh
128 atomic: bool = False, 1abfcdgeh
129 # Path
130 exists: bool = False, 1abfcdgeh
131 file_okay: bool = True, 1abfcdgeh
132 dir_okay: bool = True, 1abfcdgeh
133 writable: bool = False, 1abfcdgeh
134 readable: bool = True, 1abfcdgeh
135 resolve_path: bool = False, 1abfcdgeh
136 allow_dash: bool = False, 1abfcdgeh
137 path_type: Union[None, type[str], type[bytes]] = None, 1abfcdgeh
138 # Rich settings
139 rich_help_panel: Union[str, None] = None, 1abfcdgeh
140) -> Any: ... 1abcde
143def Option( 1abfcdgeh
144 # Parameter
145 default: Optional[Any] = ...,
146 *param_decls: str,
147 callback: Optional[Callable[..., Any]] = None,
148 metavar: Optional[str] = None,
149 expose_value: bool = True,
150 is_eager: bool = False,
151 envvar: Optional[Union[str, list[str]]] = None,
152 # Note that shell_complete is not fully supported and will be removed in future versions
153 # TODO: Remove shell_complete in a future version (after 0.16.0)
154 shell_complete: Optional[
155 Callable[
156 [click.Context, click.Parameter, str],
157 Union[list["click.shell_completion.CompletionItem"], list[str]],
158 ]
159 ] = None,
160 autocompletion: Optional[Callable[..., Any]] = None,
161 default_factory: Optional[Callable[[], Any]] = None,
162 # Custom type
163 parser: Optional[Callable[[str], Any]] = None,
164 click_type: Optional[click.ParamType] = None,
165 # Option
166 show_default: Union[bool, str] = True,
167 prompt: Union[bool, str] = False,
168 confirmation_prompt: bool = False,
169 prompt_required: bool = True,
170 hide_input: bool = False,
171 # TODO: remove is_flag and flag_value in a future release
172 is_flag: Optional[bool] = None,
173 flag_value: Optional[Any] = None,
174 count: bool = False,
175 allow_from_autoenv: bool = True,
176 help: Optional[str] = None,
177 hidden: bool = False,
178 show_choices: bool = True,
179 show_envvar: bool = True,
180 # Choice
181 case_sensitive: bool = True,
182 # Numbers
183 min: Optional[Union[int, float]] = None,
184 max: Optional[Union[int, float]] = None,
185 clamp: bool = False,
186 # DateTime
187 formats: Optional[list[str]] = None,
188 # File
189 mode: Optional[str] = None,
190 encoding: Optional[str] = None,
191 errors: Optional[str] = "strict",
192 lazy: Optional[bool] = None,
193 atomic: bool = False,
194 # Path
195 exists: bool = False,
196 file_okay: bool = True,
197 dir_okay: bool = True,
198 writable: bool = False,
199 readable: bool = True,
200 resolve_path: bool = False,
201 allow_dash: bool = False,
202 path_type: Union[None, type[str], type[bytes]] = None,
203 # Rich settings
204 rich_help_panel: Union[str, None] = None,
205) -> Any:
206 return OptionInfo( 1abfcdgeh
207 # Parameter
208 default=default,
209 param_decls=param_decls,
210 callback=callback,
211 metavar=metavar,
212 expose_value=expose_value,
213 is_eager=is_eager,
214 envvar=envvar,
215 shell_complete=shell_complete,
216 autocompletion=autocompletion,
217 default_factory=default_factory,
218 # Custom type
219 parser=parser,
220 click_type=click_type,
221 # Option
222 show_default=show_default,
223 prompt=prompt,
224 confirmation_prompt=confirmation_prompt,
225 prompt_required=prompt_required,
226 hide_input=hide_input,
227 is_flag=is_flag,
228 flag_value=flag_value,
229 count=count,
230 allow_from_autoenv=allow_from_autoenv,
231 help=help,
232 hidden=hidden,
233 show_choices=show_choices,
234 show_envvar=show_envvar,
235 # Choice
236 case_sensitive=case_sensitive,
237 # Numbers
238 min=min,
239 max=max,
240 clamp=clamp,
241 # DateTime
242 formats=formats,
243 # File
244 mode=mode,
245 encoding=encoding,
246 errors=errors,
247 lazy=lazy,
248 atomic=atomic,
249 # Path
250 exists=exists,
251 file_okay=file_okay,
252 dir_okay=dir_okay,
253 writable=writable,
254 readable=readable,
255 resolve_path=resolve_path,
256 allow_dash=allow_dash,
257 path_type=path_type,
258 # Rich settings
259 rich_help_panel=rich_help_panel,
260 )
263# Overload for Argument created with custom type 'parser'
264@overload 1abfcdgeh
265def Argument( 1abfcdgeh
266 # Parameter
267 default: Optional[Any] = ..., 1abcde
268 *,
269 callback: Optional[Callable[..., Any]] = None, 1abfcdgeh
270 metavar: Optional[str] = None, 1abfcdgeh
271 expose_value: bool = True, 1abfcdgeh
272 is_eager: bool = False, 1abfcdgeh
273 envvar: Optional[Union[str, list[str]]] = None, 1abfcdgeh
274 # Note that shell_complete is not fully supported and will be removed in future versions
275 # TODO: Remove shell_complete in a future version (after 0.16.0)
276 shell_complete: Optional[ 1abcde
277 Callable[ 1abcde
278 [click.Context, click.Parameter, str], 1abcde
279 Union[list["click.shell_completion.CompletionItem"], list[str]], 1abcde
280 ]
281 ] = None, 1abfcdgeh
282 autocompletion: Optional[Callable[..., Any]] = None, 1abfcdgeh
283 default_factory: Optional[Callable[[], Any]] = None, 1abfcdgeh
284 # Custom type
285 parser: Optional[Callable[[str], Any]] = None, 1abfcdgeh
286 # TyperArgument
287 show_default: Union[bool, str] = True, 1abfcdgeh
288 show_choices: bool = True, 1abfcdgeh
289 show_envvar: bool = True, 1abfcdgeh
290 help: Optional[str] = None, 1abfcdgeh
291 hidden: bool = False, 1abfcdgeh
292 # Choice
293 case_sensitive: bool = True, 1abfcdgeh
294 # Numbers
295 min: Optional[Union[int, float]] = None, 1abfcdgeh
296 max: Optional[Union[int, float]] = None, 1abfcdgeh
297 clamp: bool = False, 1abfcdgeh
298 # DateTime
299 formats: Optional[list[str]] = None, 1abfcdgeh
300 # File
301 mode: Optional[str] = None, 1abfcdgeh
302 encoding: Optional[str] = None, 1abfcdgeh
303 errors: Optional[str] = "strict", 1abfcdgeh
304 lazy: Optional[bool] = None, 1abfcdgeh
305 atomic: bool = False, 1abfcdgeh
306 # Path
307 exists: bool = False, 1abfcdgeh
308 file_okay: bool = True, 1abfcdgeh
309 dir_okay: bool = True, 1abfcdgeh
310 writable: bool = False, 1abfcdgeh
311 readable: bool = True, 1abfcdgeh
312 resolve_path: bool = False, 1abfcdgeh
313 allow_dash: bool = False, 1abfcdgeh
314 path_type: Union[None, type[str], type[bytes]] = None, 1abfcdgeh
315 # Rich settings
316 rich_help_panel: Union[str, None] = None, 1abfcdgeh
317) -> Any: ... 1abcde
320# Overload for Argument created with custom type 'click_type'
321@overload 1abfcdgeh
322def Argument( 1abfcdgeh
323 # Parameter
324 default: Optional[Any] = ..., 1abcde
325 *,
326 callback: Optional[Callable[..., Any]] = None, 1abfcdgeh
327 metavar: Optional[str] = None, 1abfcdgeh
328 expose_value: bool = True, 1abfcdgeh
329 is_eager: bool = False, 1abfcdgeh
330 envvar: Optional[Union[str, list[str]]] = None, 1abfcdgeh
331 # Note that shell_complete is not fully supported and will be removed in future versions
332 # TODO: Remove shell_complete in a future version (after 0.16.0)
333 shell_complete: Optional[ 1abcde
334 Callable[ 1abcde
335 [click.Context, click.Parameter, str], 1abcde
336 Union[list["click.shell_completion.CompletionItem"], list[str]], 1abcde
337 ]
338 ] = None, 1abfcdgeh
339 autocompletion: Optional[Callable[..., Any]] = None, 1abfcdgeh
340 default_factory: Optional[Callable[[], Any]] = None, 1abfcdgeh
341 # Custom type
342 click_type: Optional[click.ParamType] = None, 1abfcdgeh
343 # TyperArgument
344 show_default: Union[bool, str] = True, 1abfcdgeh
345 show_choices: bool = True, 1abfcdgeh
346 show_envvar: bool = True, 1abfcdgeh
347 help: Optional[str] = None, 1abfcdgeh
348 hidden: bool = False, 1abfcdgeh
349 # Choice
350 case_sensitive: bool = True, 1abfcdgeh
351 # Numbers
352 min: Optional[Union[int, float]] = None, 1abfcdgeh
353 max: Optional[Union[int, float]] = None, 1abfcdgeh
354 clamp: bool = False, 1abfcdgeh
355 # DateTime
356 formats: Optional[list[str]] = None, 1abfcdgeh
357 # File
358 mode: Optional[str] = None, 1abfcdgeh
359 encoding: Optional[str] = None, 1abfcdgeh
360 errors: Optional[str] = "strict", 1abfcdgeh
361 lazy: Optional[bool] = None, 1abfcdgeh
362 atomic: bool = False, 1abfcdgeh
363 # Path
364 exists: bool = False, 1abfcdgeh
365 file_okay: bool = True, 1abfcdgeh
366 dir_okay: bool = True, 1abfcdgeh
367 writable: bool = False, 1abfcdgeh
368 readable: bool = True, 1abfcdgeh
369 resolve_path: bool = False, 1abfcdgeh
370 allow_dash: bool = False, 1abfcdgeh
371 path_type: Union[None, type[str], type[bytes]] = None, 1abfcdgeh
372 # Rich settings
373 rich_help_panel: Union[str, None] = None, 1abfcdgeh
374) -> Any: ... 1abcde
377def Argument( 1abfcdgeh
378 # Parameter
379 default: Optional[Any] = ...,
380 *,
381 callback: Optional[Callable[..., Any]] = None,
382 metavar: Optional[str] = None,
383 expose_value: bool = True,
384 is_eager: bool = False,
385 envvar: Optional[Union[str, list[str]]] = None,
386 # Note that shell_complete is not fully supported and will be removed in future versions
387 # TODO: Remove shell_complete in a future version (after 0.16.0)
388 shell_complete: Optional[
389 Callable[
390 [click.Context, click.Parameter, str],
391 Union[list["click.shell_completion.CompletionItem"], list[str]],
392 ]
393 ] = None,
394 autocompletion: Optional[Callable[..., Any]] = None,
395 default_factory: Optional[Callable[[], Any]] = None,
396 # Custom type
397 parser: Optional[Callable[[str], Any]] = None,
398 click_type: Optional[click.ParamType] = None,
399 # TyperArgument
400 show_default: Union[bool, str] = True,
401 show_choices: bool = True,
402 show_envvar: bool = True,
403 help: Optional[str] = None,
404 hidden: bool = False,
405 # Choice
406 case_sensitive: bool = True,
407 # Numbers
408 min: Optional[Union[int, float]] = None,
409 max: Optional[Union[int, float]] = None,
410 clamp: bool = False,
411 # DateTime
412 formats: Optional[list[str]] = None,
413 # File
414 mode: Optional[str] = None,
415 encoding: Optional[str] = None,
416 errors: Optional[str] = "strict",
417 lazy: Optional[bool] = None,
418 atomic: bool = False,
419 # Path
420 exists: bool = False,
421 file_okay: bool = True,
422 dir_okay: bool = True,
423 writable: bool = False,
424 readable: bool = True,
425 resolve_path: bool = False,
426 allow_dash: bool = False,
427 path_type: Union[None, type[str], type[bytes]] = None,
428 # Rich settings
429 rich_help_panel: Union[str, None] = None,
430) -> Any:
431 return ArgumentInfo( 1abfcdgeh
432 # Parameter
433 default=default,
434 # Arguments can only have one param declaration
435 # it will be generated from the param name
436 param_decls=None,
437 callback=callback,
438 metavar=metavar,
439 expose_value=expose_value,
440 is_eager=is_eager,
441 envvar=envvar,
442 shell_complete=shell_complete,
443 autocompletion=autocompletion,
444 default_factory=default_factory,
445 # Custom type
446 parser=parser,
447 click_type=click_type,
448 # TyperArgument
449 show_default=show_default,
450 show_choices=show_choices,
451 show_envvar=show_envvar,
452 help=help,
453 hidden=hidden,
454 # Choice
455 case_sensitive=case_sensitive,
456 # Numbers
457 min=min,
458 max=max,
459 clamp=clamp,
460 # DateTime
461 formats=formats,
462 # File
463 mode=mode,
464 encoding=encoding,
465 errors=errors,
466 lazy=lazy,
467 atomic=atomic,
468 # Path
469 exists=exists,
470 file_okay=file_okay,
471 dir_okay=dir_okay,
472 writable=writable,
473 readable=readable,
474 resolve_path=resolve_path,
475 allow_dash=allow_dash,
476 path_type=path_type,
477 # Rich settings
478 rich_help_panel=rich_help_panel,
479 )