Coverage for typer/params.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-06-24 00:17 +0000

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

2 

3import click 1habcdefg

4 

5from .models import ArgumentInfo, OptionInfo 1habcdefg

6 

7if TYPE_CHECKING: # pragma: no cover 1habcdefg

8 import click.shell_completion 

9 

10 

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

12@overload 1habcdefg

13def Option( 1abcdefg

14 # Parameter 

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

16 *param_decls: str, 1abcdefg

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

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

19 expose_value: bool = True, 1habcdefg

20 is_eager: bool = False, 1habcdefg

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

22 shell_complete: Optional[ 1abcdefg

23 Callable[ 1abcdefg

24 [click.Context, click.Parameter, str], 1abcdefg

25 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg

26 ] 

27 ] = None, 1habcdefg

28 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg

29 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg

30 # Custom type 

31 parser: Optional[Callable[[str], Any]] = None, 1habcdefg

32 # Option 

33 show_default: Union[bool, str] = True, 1habcdefg

34 prompt: Union[bool, str] = False, 1habcdefg

35 confirmation_prompt: bool = False, 1habcdefg

36 prompt_required: bool = True, 1habcdefg

37 hide_input: bool = False, 1habcdefg

38 is_flag: Optional[bool] = None, 1habcdefg

39 flag_value: Optional[Any] = None, 1habcdefg

40 count: bool = False, 1habcdefg

41 allow_from_autoenv: bool = True, 1habcdefg

42 help: Optional[str] = None, 1habcdefg

43 hidden: bool = False, 1habcdefg

44 show_choices: bool = True, 1habcdefg

45 show_envvar: bool = True, 1habcdefg

46 # Choice 

47 case_sensitive: bool = True, 1habcdefg

48 # Numbers 

49 min: Optional[Union[int, float]] = None, 1habcdefg

50 max: Optional[Union[int, float]] = None, 1habcdefg

51 clamp: bool = False, 1habcdefg

52 # DateTime 

53 formats: Optional[List[str]] = None, 1habcdefg

54 # File 

55 mode: Optional[str] = None, 1habcdefg

56 encoding: Optional[str] = None, 1habcdefg

57 errors: Optional[str] = "strict", 1habcdefg

58 lazy: Optional[bool] = None, 1habcdefg

59 atomic: bool = False, 1habcdefg

60 # Path 

61 exists: bool = False, 1habcdefg

62 file_okay: bool = True, 1habcdefg

63 dir_okay: bool = True, 1habcdefg

64 writable: bool = False, 1habcdefg

65 readable: bool = True, 1habcdefg

66 resolve_path: bool = False, 1habcdefg

67 allow_dash: bool = False, 1habcdefg

68 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg

69 # Rich settings 

70 rich_help_panel: Union[str, None] = None, 1habcdefg

71) -> Any: 1habcdefg

72 ... 

73 

74 

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

76@overload 1habcdefg

77def Option( 1abcdefg

78 # Parameter 

79 default: Optional[Any] = ..., 1habcdefg

80 *param_decls: str, 1abcdefg

81 callback: Optional[Callable[..., Any]] = None, 1habcdefg

82 metavar: Optional[str] = None, 1habcdefg

83 expose_value: bool = True, 1habcdefg

84 is_eager: bool = False, 1habcdefg

85 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg

86 shell_complete: Optional[ 1abcdefg

87 Callable[ 1abcdefg

88 [click.Context, click.Parameter, str], 1abcdefg

89 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg

90 ] 

91 ] = None, 1habcdefg

92 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg

93 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg

94 # Custom type 

95 click_type: Optional[click.ParamType] = None, 1habcdefg

96 # Option 

97 show_default: Union[bool, str] = True, 1habcdefg

98 prompt: Union[bool, str] = False, 1habcdefg

99 confirmation_prompt: bool = False, 1habcdefg

100 prompt_required: bool = True, 1habcdefg

101 hide_input: bool = False, 1habcdefg

102 is_flag: Optional[bool] = None, 1habcdefg

103 flag_value: Optional[Any] = None, 1habcdefg

104 count: bool = False, 1habcdefg

105 allow_from_autoenv: bool = True, 1habcdefg

106 help: Optional[str] = None, 1habcdefg

107 hidden: bool = False, 1habcdefg

108 show_choices: bool = True, 1habcdefg

109 show_envvar: bool = True, 1habcdefg

110 # Choice 

111 case_sensitive: bool = True, 1habcdefg

112 # Numbers 

113 min: Optional[Union[int, float]] = None, 1habcdefg

114 max: Optional[Union[int, float]] = None, 1habcdefg

115 clamp: bool = False, 1habcdefg

116 # DateTime 

117 formats: Optional[List[str]] = None, 1habcdefg

118 # File 

119 mode: Optional[str] = None, 1habcdefg

120 encoding: Optional[str] = None, 1habcdefg

121 errors: Optional[str] = "strict", 1habcdefg

122 lazy: Optional[bool] = None, 1habcdefg

123 atomic: bool = False, 1habcdefg

124 # Path 

125 exists: bool = False, 1habcdefg

126 file_okay: bool = True, 1habcdefg

127 dir_okay: bool = True, 1habcdefg

128 writable: bool = False, 1habcdefg

129 readable: bool = True, 1habcdefg

130 resolve_path: bool = False, 1habcdefg

131 allow_dash: bool = False, 1habcdefg

132 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg

133 # Rich settings 

134 rich_help_panel: Union[str, None] = None, 1habcdefg

135) -> Any: 1habcdefg

136 ... 

137 

138 

139def Option( 1abcdefg

140 # Parameter 

141 default: Optional[Any] = ..., 

142 *param_decls: str, 

143 callback: Optional[Callable[..., Any]] = None, 

144 metavar: Optional[str] = None, 

145 expose_value: bool = True, 

146 is_eager: bool = False, 

147 envvar: Optional[Union[str, List[str]]] = None, 

148 shell_complete: Optional[ 

149 Callable[ 

150 [click.Context, click.Parameter, str], 

151 Union[List["click.shell_completion.CompletionItem"], List[str]], 

152 ] 

153 ] = None, 

154 autocompletion: Optional[Callable[..., Any]] = None, 

155 default_factory: Optional[Callable[[], Any]] = None, 

156 # Custom type 

157 parser: Optional[Callable[[str], Any]] = None, 

158 click_type: Optional[click.ParamType] = None, 

159 # Option 

160 show_default: Union[bool, str] = True, 

161 prompt: Union[bool, str] = False, 

162 confirmation_prompt: bool = False, 

163 prompt_required: bool = True, 

164 hide_input: bool = False, 

165 is_flag: Optional[bool] = None, 

166 flag_value: Optional[Any] = None, 

167 count: bool = False, 

168 allow_from_autoenv: bool = True, 

169 help: Optional[str] = None, 

170 hidden: bool = False, 

171 show_choices: bool = True, 

172 show_envvar: bool = True, 

173 # Choice 

174 case_sensitive: bool = True, 

175 # Numbers 

176 min: Optional[Union[int, float]] = None, 

177 max: Optional[Union[int, float]] = None, 

178 clamp: bool = False, 

179 # DateTime 

180 formats: Optional[List[str]] = None, 

181 # File 

182 mode: Optional[str] = None, 

183 encoding: Optional[str] = None, 

184 errors: Optional[str] = "strict", 

185 lazy: Optional[bool] = None, 

186 atomic: bool = False, 

187 # Path 

188 exists: bool = False, 

189 file_okay: bool = True, 

190 dir_okay: bool = True, 

191 writable: bool = False, 

192 readable: bool = True, 

193 resolve_path: bool = False, 

194 allow_dash: bool = False, 

195 path_type: Union[None, Type[str], Type[bytes]] = None, 

196 # Rich settings 

197 rich_help_panel: Union[str, None] = None, 

198) -> Any: 

199 return OptionInfo( 1habcdefg

200 # Parameter 

201 default=default, 

202 param_decls=param_decls, 

203 callback=callback, 

204 metavar=metavar, 

205 expose_value=expose_value, 

206 is_eager=is_eager, 

207 envvar=envvar, 

208 shell_complete=shell_complete, 

209 autocompletion=autocompletion, 

210 default_factory=default_factory, 

211 # Custom type 

212 parser=parser, 

213 click_type=click_type, 

214 # Option 

215 show_default=show_default, 

216 prompt=prompt, 

217 confirmation_prompt=confirmation_prompt, 

218 prompt_required=prompt_required, 

219 hide_input=hide_input, 

220 is_flag=is_flag, 

221 flag_value=flag_value, 

222 count=count, 

223 allow_from_autoenv=allow_from_autoenv, 

224 help=help, 

225 hidden=hidden, 

226 show_choices=show_choices, 

227 show_envvar=show_envvar, 

228 # Choice 

229 case_sensitive=case_sensitive, 

230 # Numbers 

231 min=min, 

232 max=max, 

233 clamp=clamp, 

234 # DateTime 

235 formats=formats, 

236 # File 

237 mode=mode, 

238 encoding=encoding, 

239 errors=errors, 

240 lazy=lazy, 

241 atomic=atomic, 

242 # Path 

243 exists=exists, 

244 file_okay=file_okay, 

245 dir_okay=dir_okay, 

246 writable=writable, 

247 readable=readable, 

248 resolve_path=resolve_path, 

249 allow_dash=allow_dash, 

250 path_type=path_type, 

251 # Rich settings 

252 rich_help_panel=rich_help_panel, 

253 ) 

254 

255 

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

257@overload 1habcdefg

258def Argument( 1abcdefg

259 # Parameter 

260 default: Optional[Any] = ..., 1habcdefg

261 *, 

262 callback: Optional[Callable[..., Any]] = None, 1habcdefg

263 metavar: Optional[str] = None, 1habcdefg

264 expose_value: bool = True, 1habcdefg

265 is_eager: bool = False, 1habcdefg

266 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg

267 shell_complete: Optional[ 1abcdefg

268 Callable[ 1abcdefg

269 [click.Context, click.Parameter, str], 1abcdefg

270 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg

271 ] 

272 ] = None, 1habcdefg

273 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg

274 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg

275 # Custom type 

276 parser: Optional[Callable[[str], Any]] = None, 1habcdefg

277 # TyperArgument 

278 show_default: Union[bool, str] = True, 1habcdefg

279 show_choices: bool = True, 1habcdefg

280 show_envvar: bool = True, 1habcdefg

281 help: Optional[str] = None, 1habcdefg

282 hidden: bool = False, 1habcdefg

283 # Choice 

284 case_sensitive: bool = True, 1habcdefg

285 # Numbers 

286 min: Optional[Union[int, float]] = None, 1habcdefg

287 max: Optional[Union[int, float]] = None, 1habcdefg

288 clamp: bool = False, 1habcdefg

289 # DateTime 

290 formats: Optional[List[str]] = None, 1habcdefg

291 # File 

292 mode: Optional[str] = None, 1habcdefg

293 encoding: Optional[str] = None, 1habcdefg

294 errors: Optional[str] = "strict", 1habcdefg

295 lazy: Optional[bool] = None, 1habcdefg

296 atomic: bool = False, 1habcdefg

297 # Path 

298 exists: bool = False, 1habcdefg

299 file_okay: bool = True, 1habcdefg

300 dir_okay: bool = True, 1habcdefg

301 writable: bool = False, 1habcdefg

302 readable: bool = True, 1habcdefg

303 resolve_path: bool = False, 1habcdefg

304 allow_dash: bool = False, 1habcdefg

305 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg

306 # Rich settings 

307 rich_help_panel: Union[str, None] = None, 1habcdefg

308) -> Any: 1habcdefg

309 ... 

310 

311 

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

313@overload 1habcdefg

314def Argument( 1abcdefg

315 # Parameter 

316 default: Optional[Any] = ..., 1habcdefg

317 *, 

318 callback: Optional[Callable[..., Any]] = None, 1habcdefg

319 metavar: Optional[str] = None, 1habcdefg

320 expose_value: bool = True, 1habcdefg

321 is_eager: bool = False, 1habcdefg

322 envvar: Optional[Union[str, List[str]]] = None, 1habcdefg

323 shell_complete: Optional[ 1abcdefg

324 Callable[ 1abcdefg

325 [click.Context, click.Parameter, str], 1abcdefg

326 Union[List["click.shell_completion.CompletionItem"], List[str]], 1abcdefg

327 ] 

328 ] = None, 1habcdefg

329 autocompletion: Optional[Callable[..., Any]] = None, 1habcdefg

330 default_factory: Optional[Callable[[], Any]] = None, 1habcdefg

331 # Custom type 

332 click_type: Optional[click.ParamType] = None, 1habcdefg

333 # TyperArgument 

334 show_default: Union[bool, str] = True, 1habcdefg

335 show_choices: bool = True, 1habcdefg

336 show_envvar: bool = True, 1habcdefg

337 help: Optional[str] = None, 1habcdefg

338 hidden: bool = False, 1habcdefg

339 # Choice 

340 case_sensitive: bool = True, 1habcdefg

341 # Numbers 

342 min: Optional[Union[int, float]] = None, 1habcdefg

343 max: Optional[Union[int, float]] = None, 1habcdefg

344 clamp: bool = False, 1habcdefg

345 # DateTime 

346 formats: Optional[List[str]] = None, 1habcdefg

347 # File 

348 mode: Optional[str] = None, 1habcdefg

349 encoding: Optional[str] = None, 1habcdefg

350 errors: Optional[str] = "strict", 1habcdefg

351 lazy: Optional[bool] = None, 1habcdefg

352 atomic: bool = False, 1habcdefg

353 # Path 

354 exists: bool = False, 1habcdefg

355 file_okay: bool = True, 1habcdefg

356 dir_okay: bool = True, 1habcdefg

357 writable: bool = False, 1habcdefg

358 readable: bool = True, 1habcdefg

359 resolve_path: bool = False, 1habcdefg

360 allow_dash: bool = False, 1habcdefg

361 path_type: Union[None, Type[str], Type[bytes]] = None, 1habcdefg

362 # Rich settings 

363 rich_help_panel: Union[str, None] = None, 1habcdefg

364) -> Any: 1habcdefg

365 ... 

366 

367 

368def Argument( 1abcdefg

369 # Parameter 

370 default: Optional[Any] = ..., 

371 *, 

372 callback: Optional[Callable[..., Any]] = None, 

373 metavar: Optional[str] = None, 

374 expose_value: bool = True, 

375 is_eager: bool = False, 

376 envvar: Optional[Union[str, List[str]]] = None, 

377 shell_complete: Optional[ 

378 Callable[ 

379 [click.Context, click.Parameter, str], 

380 Union[List["click.shell_completion.CompletionItem"], List[str]], 

381 ] 

382 ] = None, 

383 autocompletion: Optional[Callable[..., Any]] = None, 

384 default_factory: Optional[Callable[[], Any]] = None, 

385 # Custom type 

386 parser: Optional[Callable[[str], Any]] = None, 

387 click_type: Optional[click.ParamType] = None, 

388 # TyperArgument 

389 show_default: Union[bool, str] = True, 

390 show_choices: bool = True, 

391 show_envvar: bool = True, 

392 help: Optional[str] = None, 

393 hidden: bool = False, 

394 # Choice 

395 case_sensitive: bool = True, 

396 # Numbers 

397 min: Optional[Union[int, float]] = None, 

398 max: Optional[Union[int, float]] = None, 

399 clamp: bool = False, 

400 # DateTime 

401 formats: Optional[List[str]] = None, 

402 # File 

403 mode: Optional[str] = None, 

404 encoding: Optional[str] = None, 

405 errors: Optional[str] = "strict", 

406 lazy: Optional[bool] = None, 

407 atomic: bool = False, 

408 # Path 

409 exists: bool = False, 

410 file_okay: bool = True, 

411 dir_okay: bool = True, 

412 writable: bool = False, 

413 readable: bool = True, 

414 resolve_path: bool = False, 

415 allow_dash: bool = False, 

416 path_type: Union[None, Type[str], Type[bytes]] = None, 

417 # Rich settings 

418 rich_help_panel: Union[str, None] = None, 

419) -> Any: 

420 return ArgumentInfo( 1habcdefg

421 # Parameter 

422 default=default, 

423 # Arguments can only have one param declaration 

424 # it will be generated from the param name 

425 param_decls=None, 

426 callback=callback, 

427 metavar=metavar, 

428 expose_value=expose_value, 

429 is_eager=is_eager, 

430 envvar=envvar, 

431 shell_complete=shell_complete, 

432 autocompletion=autocompletion, 

433 default_factory=default_factory, 

434 # Custom type 

435 parser=parser, 

436 click_type=click_type, 

437 # TyperArgument 

438 show_default=show_default, 

439 show_choices=show_choices, 

440 show_envvar=show_envvar, 

441 help=help, 

442 hidden=hidden, 

443 # Choice 

444 case_sensitive=case_sensitive, 

445 # Numbers 

446 min=min, 

447 max=max, 

448 clamp=clamp, 

449 # DateTime 

450 formats=formats, 

451 # File 

452 mode=mode, 

453 encoding=encoding, 

454 errors=errors, 

455 lazy=lazy, 

456 atomic=atomic, 

457 # Path 

458 exists=exists, 

459 file_okay=file_okay, 

460 dir_okay=dir_okay, 

461 writable=writable, 

462 readable=readable, 

463 resolve_path=resolve_path, 

464 allow_dash=allow_dash, 

465 path_type=path_type, 

466 # Rich settings 

467 rich_help_panel=rich_help_panel, 

468 )