|
13 | 13 | deque,
|
14 | 14 | )
|
15 | 15 | from typing import (
|
16 |
| - Any, |
17 | 16 | Dict,
|
18 | 17 | List,
|
19 | 18 | Optional,
|
|
27 | 26 | constants,
|
28 | 27 | )
|
29 | 28 | from .argparse_custom import (
|
30 |
| - ATTR_CHOICES_CALLABLE, |
31 |
| - ATTR_DESCRIPTIVE_COMPLETION_HEADER, |
32 |
| - ATTR_NARGS_RANGE, |
33 |
| - ATTR_SUPPRESS_TAB_HINT, |
34 | 29 | ChoicesCallable,
|
35 |
| - ChoicesProviderFuncBase, |
36 | 30 | ChoicesProviderFuncWithTokens,
|
37 | 31 | CompletionItem,
|
38 | 32 | generate_range_error,
|
|
60 | 54 | def _build_hint(parser: argparse.ArgumentParser, arg_action: argparse.Action) -> str:
|
61 | 55 | """Build tab completion hint for a given argument"""
|
62 | 56 | # Check if hinting is disabled for this argument
|
63 |
| - suppress_hint = getattr(arg_action, ATTR_SUPPRESS_TAB_HINT, False) |
| 57 | + suppress_hint = arg_action.get_suppress_tab_hint() # type: ignore[attr-defined] |
64 | 58 | if suppress_hint or arg_action.help == argparse.SUPPRESS:
|
65 | 59 | return ''
|
66 | 60 | else:
|
@@ -116,7 +110,7 @@ def __init__(self, arg_action: argparse.Action) -> None:
|
116 | 110 | self.is_remainder = self.action.nargs == argparse.REMAINDER
|
117 | 111 |
|
118 | 112 | # Check if nargs is a range
|
119 |
| - nargs_range = getattr(self.action, ATTR_NARGS_RANGE, None) |
| 113 | + nargs_range = self.action.get_nargs_range() # type: ignore[attr-defined] |
120 | 114 | if nargs_range is not None:
|
121 | 115 | self.min = nargs_range[0]
|
122 | 116 | self.max = nargs_range[1]
|
@@ -562,7 +556,7 @@ def _format_completions(self, arg_state: _ArgumentState, completions: Union[List
|
562 | 556 | tuple_index = min(len(destination) - 1, arg_state.count)
|
563 | 557 | destination = destination[tuple_index]
|
564 | 558 |
|
565 |
| - desc_header = getattr(arg_state.action, ATTR_DESCRIPTIVE_COMPLETION_HEADER, None) |
| 559 | + desc_header = arg_state.action.get_descriptive_header() # type: ignore[attr-defined] |
566 | 560 | if desc_header is None:
|
567 | 561 | desc_header = DEFAULT_DESCRIPTIVE_HEADER
|
568 | 562 |
|
@@ -665,7 +659,7 @@ def _complete_arg(
|
665 | 659 | if not isinstance(choice, str):
|
666 | 660 | arg_choices[index] = str(choice) # type: ignore[unreachable]
|
667 | 661 | else:
|
668 |
| - choices_attr = getattr(arg_state.action, ATTR_CHOICES_CALLABLE, None) |
| 662 | + choices_attr = arg_state.action.get_choices_callable() # type: ignore[attr-defined] |
669 | 663 | if choices_attr is None:
|
670 | 664 | return []
|
671 | 665 | arg_choices = choices_attr
|
|
0 commit comments