Coverage for typer/params.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-04-14 00:18 +0000

1from typing import TYPE_CHECKING, Any, Callable, List, Optional, Type, Union, overload 1iabcdefgh

2 

3import click 1iabcdefgh

4 

5from .models import ArgumentInfo, OptionInfo 1iabcdefgh

6 

7if TYPE_CHECKING: # pragma: no cover 1iabcdefgh

8 import click.shell_completion 

9 

10 

11# Overload for Option created with custom type 'parser' 

12@overload 1iabcdefgh

13def Option( 1abcdefgh

14 # Parameter 

15 default: Optional[Any] = ..., 1iabcdefgh

16 *param_decls: str, 1abcdefgh

17 callback: Optional[Callable[..., Any]] = None, 1iabcdefgh

18 metavar: Optional[str] = None, 1iabcdefgh

19 expose_value: bool = True, 1iabcdefgh

20 is_eager: bool = False, 1iabcdefgh

21 envvar: Optional[Union[str, List[str]]] = None, 1iabcdefgh

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[ 1abcdefgh

25 Callable[ 1abcdefgh

26 [click.Context, click.Parameter, str], 1abcdefgh

27 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefgh

28 ] 

29 ] = None, 1iabcdefgh

30 autocompletion: Optional[Callable[..., Any]] = None, 1iabcdefgh

31 default_factory: Optional[Callable[[], Any]] = None, 1iabcdefgh

32 # Custom type 

33 parser: Optional[Callable[[str], Any]] = None, 1iabcdefgh

34 # Option 

35 show_default: Union[bool, str] = True, 1iabcdefgh

36 prompt: Union[bool, str] = False, 1iabcdefgh

37 confirmation_prompt: bool = False, 1iabcdefgh

38 prompt_required: bool = True, 1iabcdefgh

39 hide_input: bool = False, 1iabcdefgh

40 # TODO: remove is_flag and flag_value in a future release 

41 is_flag: Optional[bool] = None, 1iabcdefgh

42 flag_value: Optional[Any] = None, 1iabcdefgh

43 count: bool = False, 1iabcdefgh

44 allow_from_autoenv: bool = True, 1iabcdefgh

45 help: Optional[str] = None, 1iabcdefgh

46 hidden: bool = False, 1iabcdefgh

47 show_choices: bool = True, 1iabcdefgh

48 show_envvar: bool = True, 1iabcdefgh

49 # Choice 

50 case_sensitive: bool = True, 1iabcdefgh

51 # Numbers 

52 min: Optional[Union[int, float]] = None, 1iabcdefgh

53 max: Optional[Union[int, float]] = None, 1iabcdefgh

54 clamp: bool = False, 1iabcdefgh

55 # DateTime 

56 formats: Optional[List[str]] = None, 1iabcdefgh

57 # File 

58 mode: Optional[str] = None, 1iabcdefgh

59 encoding: Optional[str] = None, 1iabcdefgh

60 errors: Optional[str] = "strict", 1iabcdefgh

61 lazy: Optional[bool] = None, 1iabcdefgh

62 atomic: bool = False, 1iabcdefgh

63 # Path 

64 exists: bool = False, 1iabcdefgh

65 file_okay: bool = True, 1iabcdefgh

66 dir_okay: bool = True, 1iabcdefgh

67 writable: bool = False, 1iabcdefgh

68 readable: bool = True, 1iabcdefgh

69 resolve_path: bool = False, 1iabcdefgh

70 allow_dash: bool = False, 1iabcdefgh

71 path_type: Union[None, Type[str], Type[bytes]] = None, 1iabcdefgh

72 # Rich settings 

73 rich_help_panel: Union[str, None] = None, 1iabcdefgh

74) -> Any: ... 1iabcdefgh

75 

76 

77# Overload for Option created with custom type 'click_type' 

78@overload 1iabcdefgh

79def Option( 1abcdefgh

80 # Parameter 

81 default: Optional[Any] = ..., 1iabcdefgh

82 *param_decls: str, 1abcdefgh

83 callback: Optional[Callable[..., Any]] = None, 1iabcdefgh

84 metavar: Optional[str] = None, 1iabcdefgh

85 expose_value: bool = True, 1iabcdefgh

86 is_eager: bool = False, 1iabcdefgh

87 envvar: Optional[Union[str, List[str]]] = None, 1iabcdefgh

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[ 1abcdefgh

91 Callable[ 1abcdefgh

92 [click.Context, click.Parameter, str], 1abcdefgh

93 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefgh

94 ] 

95 ] = None, 1iabcdefgh

96 autocompletion: Optional[Callable[..., Any]] = None, 1iabcdefgh

97 default_factory: Optional[Callable[[], Any]] = None, 1iabcdefgh

98 # Custom type 

99 click_type: Optional[click.ParamType] = None, 1iabcdefgh

100 # Option 

101 show_default: Union[bool, str] = True, 1iabcdefgh

102 prompt: Union[bool, str] = False, 1iabcdefgh

103 confirmation_prompt: bool = False, 1iabcdefgh

104 prompt_required: bool = True, 1iabcdefgh

105 hide_input: bool = False, 1iabcdefgh

106 # TODO: remove is_flag and flag_value in a future release 

107 is_flag: Optional[bool] = None, 1iabcdefgh

108 flag_value: Optional[Any] = None, 1iabcdefgh

109 count: bool = False, 1iabcdefgh

110 allow_from_autoenv: bool = True, 1iabcdefgh

111 help: Optional[str] = None, 1iabcdefgh

112 hidden: bool = False, 1iabcdefgh

113 show_choices: bool = True, 1iabcdefgh

114 show_envvar: bool = True, 1iabcdefgh

115 # Choice 

116 case_sensitive: bool = True, 1iabcdefgh

117 # Numbers 

118 min: Optional[Union[int, float]] = None, 1iabcdefgh

119 max: Optional[Union[int, float]] = None, 1iabcdefgh

120 clamp: bool = False, 1iabcdefgh

121 # DateTime 

122 formats: Optional[List[str]] = None, 1iabcdefgh

123 # File 

124 mode: Optional[str] = None, 1iabcdefgh

125 encoding: Optional[str] = None, 1iabcdefgh

126 errors: Optional[str] = "strict", 1iabcdefgh

127 lazy: Optional[bool] = None, 1iabcdefgh

128 atomic: bool = False, 1iabcdefgh

129 # Path 

130 exists: bool = False, 1iabcdefgh

131 file_okay: bool = True, 1iabcdefgh

132 dir_okay: bool = True, 1iabcdefgh

133 writable: bool = False, 1iabcdefgh

134 readable: bool = True, 1iabcdefgh

135 resolve_path: bool = False, 1iabcdefgh

136 allow_dash: bool = False, 1iabcdefgh

137 path_type: Union[None, Type[str], Type[bytes]] = None, 1iabcdefgh

138 # Rich settings 

139 rich_help_panel: Union[str, None] = None, 1iabcdefgh

140) -> Any: ... 1iabcdefgh

141 

142 

143def Option( 1abcdefgh

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( 1iabcdefgh

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 ) 

261 

262 

263# Overload for Argument created with custom type 'parser' 

264@overload 1iabcdefgh

265def Argument( 1abcdefgh

266 # Parameter 

267 default: Optional[Any] = ..., 1iabcdefgh

268 *, 

269 callback: Optional[Callable[..., Any]] = None, 1iabcdefgh

270 metavar: Optional[str] = None, 1iabcdefgh

271 expose_value: bool = True, 1iabcdefgh

272 is_eager: bool = False, 1iabcdefgh

273 envvar: Optional[Union[str, List[str]]] = None, 1iabcdefgh

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[ 1abcdefgh

277 Callable[ 1abcdefgh

278 [click.Context, click.Parameter, str], 1abcdefgh

279 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefgh

280 ] 

281 ] = None, 1iabcdefgh

282 autocompletion: Optional[Callable[..., Any]] = None, 1iabcdefgh

283 default_factory: Optional[Callable[[], Any]] = None, 1iabcdefgh

284 # Custom type 

285 parser: Optional[Callable[[str], Any]] = None, 1iabcdefgh

286 # TyperArgument 

287 show_default: Union[bool, str] = True, 1iabcdefgh

288 show_choices: bool = True, 1iabcdefgh

289 show_envvar: bool = True, 1iabcdefgh

290 help: Optional[str] = None, 1iabcdefgh

291 hidden: bool = False, 1iabcdefgh

292 # Choice 

293 case_sensitive: bool = True, 1iabcdefgh

294 # Numbers 

295 min: Optional[Union[int, float]] = None, 1iabcdefgh

296 max: Optional[Union[int, float]] = None, 1iabcdefgh

297 clamp: bool = False, 1iabcdefgh

298 # DateTime 

299 formats: Optional[List[str]] = None, 1iabcdefgh

300 # File 

301 mode: Optional[str] = None, 1iabcdefgh

302 encoding: Optional[str] = None, 1iabcdefgh

303 errors: Optional[str] = "strict", 1iabcdefgh

304 lazy: Optional[bool] = None, 1iabcdefgh

305 atomic: bool = False, 1iabcdefgh

306 # Path 

307 exists: bool = False, 1iabcdefgh

308 file_okay: bool = True, 1iabcdefgh

309 dir_okay: bool = True, 1iabcdefgh

310 writable: bool = False, 1iabcdefgh

311 readable: bool = True, 1iabcdefgh

312 resolve_path: bool = False, 1iabcdefgh

313 allow_dash: bool = False, 1iabcdefgh

314 path_type: Union[None, Type[str], Type[bytes]] = None, 1iabcdefgh

315 # Rich settings 

316 rich_help_panel: Union[str, None] = None, 1iabcdefgh

317) -> Any: ... 1iabcdefgh

318 

319 

320# Overload for Argument created with custom type 'click_type' 

321@overload 1iabcdefgh

322def Argument( 1abcdefgh

323 # Parameter 

324 default: Optional[Any] = ..., 1iabcdefgh

325 *, 

326 callback: Optional[Callable[..., Any]] = None, 1iabcdefgh

327 metavar: Optional[str] = None, 1iabcdefgh

328 expose_value: bool = True, 1iabcdefgh

329 is_eager: bool = False, 1iabcdefgh

330 envvar: Optional[Union[str, List[str]]] = None, 1iabcdefgh

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[ 1abcdefgh

334 Callable[ 1abcdefgh

335 [click.Context, click.Parameter, str], 1abcdefgh

336 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefgh

337 ] 

338 ] = None, 1iabcdefgh

339 autocompletion: Optional[Callable[..., Any]] = None, 1iabcdefgh

340 default_factory: Optional[Callable[[], Any]] = None, 1iabcdefgh

341 # Custom type 

342 click_type: Optional[click.ParamType] = None, 1iabcdefgh

343 # TyperArgument 

344 show_default: Union[bool, str] = True, 1iabcdefgh

345 show_choices: bool = True, 1iabcdefgh

346 show_envvar: bool = True, 1iabcdefgh

347 help: Optional[str] = None, 1iabcdefgh

348 hidden: bool = False, 1iabcdefgh

349 # Choice 

350 case_sensitive: bool = True, 1iabcdefgh

351 # Numbers 

352 min: Optional[Union[int, float]] = None, 1iabcdefgh

353 max: Optional[Union[int, float]] = None, 1iabcdefgh

354 clamp: bool = False, 1iabcdefgh

355 # DateTime 

356 formats: Optional[List[str]] = None, 1iabcdefgh

357 # File 

358 mode: Optional[str] = None, 1iabcdefgh

359 encoding: Optional[str] = None, 1iabcdefgh

360 errors: Optional[str] = "strict", 1iabcdefgh

361 lazy: Optional[bool] = None, 1iabcdefgh

362 atomic: bool = False, 1iabcdefgh

363 # Path 

364 exists: bool = False, 1iabcdefgh

365 file_okay: bool = True, 1iabcdefgh

366 dir_okay: bool = True, 1iabcdefgh

367 writable: bool = False, 1iabcdefgh

368 readable: bool = True, 1iabcdefgh

369 resolve_path: bool = False, 1iabcdefgh

370 allow_dash: bool = False, 1iabcdefgh

371 path_type: Union[None, Type[str], Type[bytes]] = None, 1iabcdefgh

372 # Rich settings 

373 rich_help_panel: Union[str, None] = None, 1iabcdefgh

374) -> Any: ... 1iabcdefgh

375 

376 

377def Argument( 1abcdefgh

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( 1iabcdefgh

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 )