Keeps state of an argument being parsed.
| 94 | |
| 95 | |
| 96 | class _ArgumentState: |
| 97 | """Keeps state of an argument being parsed.""" |
| 98 | |
| 99 | def __init__(self, arg_action: argparse.Action) -> None: |
| 100 | self.action = arg_action |
| 101 | self.min: int |
| 102 | self.max: float | int |
| 103 | self.count = 0 |
| 104 | self.is_remainder = self.action.nargs == argparse.REMAINDER |
| 105 | |
| 106 | # Check if nargs is a range |
| 107 | nargs_range: tuple[int, int | float] | None = self.action.get_nargs_range() # type: ignore[attr-defined] |
| 108 | if nargs_range is not None: |
| 109 | self.min = nargs_range[0] |
| 110 | self.max = nargs_range[1] |
| 111 | |
| 112 | # Otherwise check against argparse types |
| 113 | elif self.action.nargs is None: |
| 114 | self.min = 1 |
| 115 | self.max = 1 |
| 116 | elif self.action.nargs == argparse.OPTIONAL: |
| 117 | self.min = 0 |
| 118 | self.max = 1 |
| 119 | elif self.action.nargs in (argparse.ZERO_OR_MORE, argparse.REMAINDER): |
| 120 | self.min = 0 |
| 121 | self.max = INFINITY |
| 122 | elif self.action.nargs == argparse.ONE_OR_MORE: |
| 123 | self.min = 1 |
| 124 | self.max = INFINITY |
| 125 | else: |
| 126 | self.min = cast(int, self.action.nargs) |
| 127 | self.max = cast(int, self.action.nargs) |
| 128 | |
| 129 | |
| 130 | class _UnfinishedFlagError(CompletionError): |
no outgoing calls
no test coverage detected
searching dependent graphs…