Coverage for typer/params.py: 100%
7 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-19 20:29 +0000
1from typing import TYPE_CHECKING, Any, Callable, List, Optional, Type, Union, overload 1abgcdhefi
3import click 1abgcdhefi
5from .models import ArgumentInfo, OptionInfo 1abgcdhefi
7if TYPE_CHECKING: # pragma: no cover 1abgcdhefi
8 import click.shell_completion
11# Overload for Option created with custom type 'parser'
12@overload 1abgcdhefi
13def Option( 1abgcdhefi
14 # Parameter
15 default: Optional[Any] = ..., 1abcdef
16 *param_decls: str, 1abcdef
17 callback: Optional[Callable[..., Any]] = None, 1abgcdhefi
18 metavar: Optional[str] = None, 1abgcdhefi
19 expose_value: bool = True, 1abgcdhefi
20 is_eager: bool = False, 1abgcdhefi
21 envvar: Optional[Union[str, List[str]]] = None, 1abgcdhefi
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[ 1abcdef
25 Callable[ 1abcdef
26 [click.Context, click.Parameter, str], 1abcdef
27 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdef
28 ]
29 ] = None, 1abgcdhefi
30 autocompletion: Optional[Callable[..., Any]] = None, 1abgcdhefi
31 default_factory: Optional[Callable[[], Any]] = None, 1abgcdhefi
32 # Custom type
33 parser: Optional[Callable[[str], Any]] = None, 1abgcdhefi
34 # Option
35 show_default: Union[bool, str] = True, 1abgcdhefi
36 prompt: Union[bool, str] = False, 1abgcdhefi
37 confirmation_prompt: bool = False, 1abgcdhefi
38 prompt_required: bool = True, 1abgcdhefi
39 hide_input: bool = False, 1abgcdhefi
40 # TODO: remove is_flag and flag_value in a future release
41 is_flag: Optional[bool] = None, 1abgcdhefi
42 flag_value: Optional[Any] = None, 1abgcdhefi
43 count: bool = False, 1abgcdhefi
44 allow_from_autoenv: bool = True, 1abgcdhefi
45 help: Optional[str] = None, 1abgcdhefi
46 hidden: bool = False, 1abgcdhefi
47 show_choices: bool = True, 1abgcdhefi
48 show_envvar: bool = True, 1abgcdhefi
49 # Choice
50 case_sensitive: bool = True, 1abgcdhefi
51 # Numbers
52 min: Optional[Union[int, float]] = None, 1abgcdhefi
53 max: Optional[Union[int, float]] = None, 1abgcdhefi
54 clamp: bool = False, 1abgcdhefi
55 # DateTime
56 formats: Optional[List[str]] = None, 1abgcdhefi
57 # File
58 mode: Optional[str] = None, 1abgcdhefi
59 encoding: Optional[str] = None, 1abgcdhefi
60 errors: Optional[str] = "strict", 1abgcdhefi
61 lazy: Optional[bool] = None, 1abgcdhefi
62 atomic: bool = False, 1abgcdhefi
63 # Path
64 exists: bool = False, 1abgcdhefi
65 file_okay: bool = True, 1abgcdhefi
66 dir_okay: bool = True, 1abgcdhefi
67 writable: bool = False, 1abgcdhefi
68 readable: bool = True, 1abgcdhefi
69 resolve_path: bool = False, 1abgcdhefi
70 allow_dash: bool = False, 1abgcdhefi
71 path_type: Union[None, Type[str], Type[bytes]] = None, 1abgcdhefi
72 # Rich settings
73 rich_help_panel: Union[str, None] = None, 1abgcdhefi
74) -> Any: ... 1abcdef
77# Overload for Option created with custom type 'click_type'
78@overload 1abgcdhefi
79def Option( 1abgcdhefi
80 # Parameter
81 default: Optional[Any] = ..., 1abcdef
82 *param_decls: str, 1abcdef
83 callback: Optional[Callable[..., Any]] = None, 1abgcdhefi
84 metavar: Optional[str] = None, 1abgcdhefi
85 expose_value: bool = True, 1abgcdhefi
86 is_eager: bool = False, 1abgcdhefi
87 envvar: Optional[Union[str, List[str]]] = None, 1abgcdhefi
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[ 1abcdef
91 Callable[ 1abcdef
92 [click.Context, click.Parameter, str], 1abcdef
93 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdef
94 ]
95 ] = None, 1abgcdhefi
96 autocompletion: Optional[Callable[..., Any]] = None, 1abgcdhefi
97 default_factory: Optional[Callable[[], Any]] = None, 1abgcdhefi
98 # Custom type
99 click_type: Optional[click.ParamType] = None, 1abgcdhefi
100 # Option
101 show_default: Union[bool, str] = True, 1abgcdhefi
102 prompt: Union[bool, str] = False, 1abgcdhefi
103 confirmation_prompt: bool = False, 1abgcdhefi
104 prompt_required: bool = True, 1abgcdhefi
105 hide_input: bool = False, 1abgcdhefi
106 # TODO: remove is_flag and flag_value in a future release
107 is_flag: Optional[bool] = None, 1abgcdhefi
108 flag_value: Optional[Any] = None, 1abgcdhefi
109 count: bool = False, 1abgcdhefi
110 allow_from_autoenv: bool = True, 1abgcdhefi
111 help: Optional[str] = None, 1abgcdhefi
112 hidden: bool = False, 1abgcdhefi
113 show_choices: bool = True, 1abgcdhefi
114 show_envvar: bool = True, 1abgcdhefi
115 # Choice
116 case_sensitive: bool = True, 1abgcdhefi
117 # Numbers
118 min: Optional[Union[int, float]] = None, 1abgcdhefi
119 max: Optional[Union[int, float]] = None, 1abgcdhefi
120 clamp: bool = False, 1abgcdhefi
121 # DateTime
122 formats: Optional[List[str]] = None, 1abgcdhefi
123 # File
124 mode: Optional[str] = None, 1abgcdhefi
125 encoding: Optional[str] = None, 1abgcdhefi
126 errors: Optional[str] = "strict", 1abgcdhefi
127 lazy: Optional[bool] = None, 1abgcdhefi
128 atomic: bool = False, 1abgcdhefi
129 # Path
130 exists: bool = False, 1abgcdhefi
131 file_okay: bool = True, 1abgcdhefi
132 dir_okay: bool = True, 1abgcdhefi
133 writable: bool = False, 1abgcdhefi
134 readable: bool = True, 1abgcdhefi
135 resolve_path: bool = False, 1abgcdhefi
136 allow_dash: bool = False, 1abgcdhefi
137 path_type: Union[None, Type[str], Type[bytes]] = None, 1abgcdhefi
138 # Rich settings
139 rich_help_panel: Union[str, None] = None, 1abgcdhefi
140) -> Any: ... 1abcdef
143def Option( 1abgcdhefi
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( 1abgcdhefi
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 1abgcdhefi
265def Argument( 1abgcdhefi
266 # Parameter
267 default: Optional[Any] = ..., 1abcdef
268 *,
269 callback: Optional[Callable[..., Any]] = None, 1abgcdhefi
270 metavar: Optional[str] = None, 1abgcdhefi
271 expose_value: bool = True, 1abgcdhefi
272 is_eager: bool = False, 1abgcdhefi
273 envvar: Optional[Union[str, List[str]]] = None, 1abgcdhefi
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[ 1abcdef
277 Callable[ 1abcdef
278 [click.Context, click.Parameter, str], 1abcdef
279 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdef
280 ]
281 ] = None, 1abgcdhefi
282 autocompletion: Optional[Callable[..., Any]] = None, 1abgcdhefi
283 default_factory: Optional[Callable[[], Any]] = None, 1abgcdhefi
284 # Custom type
285 parser: Optional[Callable[[str], Any]] = None, 1abgcdhefi
286 # TyperArgument
287 show_default: Union[bool, str] = True, 1abgcdhefi
288 show_choices: bool = True, 1abgcdhefi
289 show_envvar: bool = True, 1abgcdhefi
290 help: Optional[str] = None, 1abgcdhefi
291 hidden: bool = False, 1abgcdhefi
292 # Choice
293 case_sensitive: bool = True, 1abgcdhefi
294 # Numbers
295 min: Optional[Union[int, float]] = None, 1abgcdhefi
296 max: Optional[Union[int, float]] = None, 1abgcdhefi
297 clamp: bool = False, 1abgcdhefi
298 # DateTime
299 formats: Optional[List[str]] = None, 1abgcdhefi
300 # File
301 mode: Optional[str] = None, 1abgcdhefi
302 encoding: Optional[str] = None, 1abgcdhefi
303 errors: Optional[str] = "strict", 1abgcdhefi
304 lazy: Optional[bool] = None, 1abgcdhefi
305 atomic: bool = False, 1abgcdhefi
306 # Path
307 exists: bool = False, 1abgcdhefi
308 file_okay: bool = True, 1abgcdhefi
309 dir_okay: bool = True, 1abgcdhefi
310 writable: bool = False, 1abgcdhefi
311 readable: bool = True, 1abgcdhefi
312 resolve_path: bool = False, 1abgcdhefi
313 allow_dash: bool = False, 1abgcdhefi
314 path_type: Union[None, Type[str], Type[bytes]] = None, 1abgcdhefi
315 # Rich settings
316 rich_help_panel: Union[str, None] = None, 1abgcdhefi
317) -> Any: ... 1abcdef
320# Overload for Argument created with custom type 'click_type'
321@overload 1abgcdhefi
322def Argument( 1abgcdhefi
323 # Parameter
324 default: Optional[Any] = ..., 1abcdef
325 *,
326 callback: Optional[Callable[..., Any]] = None, 1abgcdhefi
327 metavar: Optional[str] = None, 1abgcdhefi
328 expose_value: bool = True, 1abgcdhefi
329 is_eager: bool = False, 1abgcdhefi
330 envvar: Optional[Union[str, List[str]]] = None, 1abgcdhefi
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[ 1abcdef
334 Callable[ 1abcdef
335 [click.Context, click.Parameter, str], 1abcdef
336 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdef
337 ]
338 ] = None, 1abgcdhefi
339 autocompletion: Optional[Callable[..., Any]] = None, 1abgcdhefi
340 default_factory: Optional[Callable[[], Any]] = None, 1abgcdhefi
341 # Custom type
342 click_type: Optional[click.ParamType] = None, 1abgcdhefi
343 # TyperArgument
344 show_default: Union[bool, str] = True, 1abgcdhefi
345 show_choices: bool = True, 1abgcdhefi
346 show_envvar: bool = True, 1abgcdhefi
347 help: Optional[str] = None, 1abgcdhefi
348 hidden: bool = False, 1abgcdhefi
349 # Choice
350 case_sensitive: bool = True, 1abgcdhefi
351 # Numbers
352 min: Optional[Union[int, float]] = None, 1abgcdhefi
353 max: Optional[Union[int, float]] = None, 1abgcdhefi
354 clamp: bool = False, 1abgcdhefi
355 # DateTime
356 formats: Optional[List[str]] = None, 1abgcdhefi
357 # File
358 mode: Optional[str] = None, 1abgcdhefi
359 encoding: Optional[str] = None, 1abgcdhefi
360 errors: Optional[str] = "strict", 1abgcdhefi
361 lazy: Optional[bool] = None, 1abgcdhefi
362 atomic: bool = False, 1abgcdhefi
363 # Path
364 exists: bool = False, 1abgcdhefi
365 file_okay: bool = True, 1abgcdhefi
366 dir_okay: bool = True, 1abgcdhefi
367 writable: bool = False, 1abgcdhefi
368 readable: bool = True, 1abgcdhefi
369 resolve_path: bool = False, 1abgcdhefi
370 allow_dash: bool = False, 1abgcdhefi
371 path_type: Union[None, Type[str], Type[bytes]] = None, 1abgcdhefi
372 # Rich settings
373 rich_help_panel: Union[str, None] = None, 1abgcdhefi
374) -> Any: ... 1abcdef
377def Argument( 1abgcdhefi
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( 1abgcdhefi
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 )