|
6 | 6 | from collections import defaultdict |
7 | 7 | from gettext import gettext as _ |
8 | 8 | from os import getenv |
9 | | -from typing import Any, Callable, DefaultDict, Dict, Iterable, List, Optional, Union |
| 9 | +from typing import Any, DefaultDict, Dict, Iterable, List, Optional, Protocol, Union |
10 | 10 |
|
11 | 11 | import click |
12 | 12 | from rich import box |
@@ -549,30 +549,40 @@ def _print_commands_panel( |
549 | 549 | ) |
550 | 550 |
|
551 | 551 |
|
552 | | -# Define acceptable function to pass as print_options_panel_func |
553 | | -PrintOptionsPanelFunc = Callable[ |
554 | | - [ |
555 | | - str, |
556 | | - Union[List[click.Option], List[click.Argument]], |
557 | | - click.Context, |
558 | | - MarkupMode, |
559 | | - Console |
560 | | - ], |
561 | | - None |
562 | | -] |
563 | | - |
564 | | - |
565 | | -# Define acceptable function to pass as print_options_panel_func |
566 | | -PrintCommandsPanelFunc = Callable[ |
567 | | - [ |
568 | | - str, |
569 | | - List[click.Command], |
570 | | - MarkupMode, |
571 | | - Console, |
572 | | - int |
573 | | - ], |
574 | | - None |
575 | | -] |
| 552 | +class PrintOptionsPanelFunc(Protocol): |
| 553 | + """ |
| 554 | + Define acceptable function to pass as print_options_panel_func |
| 555 | +
|
| 556 | + TODO: switch to using NamedArg once minimum supported python is 3.12 |
| 557 | + """ |
| 558 | + |
| 559 | + def __call__( |
| 560 | + self, |
| 561 | + *, |
| 562 | + name: str, |
| 563 | + params: Union[List[click.Option], List[click.Argument]], |
| 564 | + ctx: click.Context, |
| 565 | + markup_mode: MarkupMode, |
| 566 | + console: Console, |
| 567 | + ) -> None: ... |
| 568 | + |
| 569 | + |
| 570 | +class PrintCommandsPanelFunc(Protocol): |
| 571 | + """ |
| 572 | + Define acceptable function to pass as print_options_panel_func |
| 573 | +
|
| 574 | + TODO: switch to using NamedArg once minimum supported python is 3.12 |
| 575 | + """ |
| 576 | + |
| 577 | + def __call__( |
| 578 | + self, |
| 579 | + *, |
| 580 | + name: str, |
| 581 | + commands: List[click.Command], |
| 582 | + markup_mode: MarkupMode, |
| 583 | + console: Console, |
| 584 | + cmd_len: int, |
| 585 | + ) -> None: ... |
576 | 586 |
|
577 | 587 |
|
578 | 588 | def rich_format_help( |
|
0 commit comments