Manage mutually exclusive group constraints and argument pruning for a given action. If an action belongs to a mutually exclusive group, this method ensures no other member has been used and updates the parser state to "consume" all remaining conflicting arguments. :raises
(
self,
arg_action: argparse.Action,
completed_mutex_groups: dict[argparse._MutuallyExclusiveGroup, argparse.Action],
used_flags: set[str],
remaining_positionals: deque[argparse.Action],
)
| 412 | ) |
| 413 | |
| 414 | def _update_mutex_groups( |
| 415 | self, |
| 416 | arg_action: argparse.Action, |
| 417 | completed_mutex_groups: dict[argparse._MutuallyExclusiveGroup, argparse.Action], |
| 418 | used_flags: set[str], |
| 419 | remaining_positionals: deque[argparse.Action], |
| 420 | ) -> None: |
| 421 | """Manage mutually exclusive group constraints and argument pruning for a given action. |
| 422 | |
| 423 | If an action belongs to a mutually exclusive group, this method ensures no other member |
| 424 | has been used and updates the parser state to "consume" all remaining conflicting arguments. |
| 425 | |
| 426 | :raises CompletionError: if another member of the same mutually exclusive group |
| 427 | has already been used. |
| 428 | """ |
| 429 | # Check if this action is in a mutually exclusive group |
| 430 | for group in self._parser._mutually_exclusive_groups: |
| 431 | if arg_action in group._group_actions: |
| 432 | # Check if the group this action belongs to has already been completed |
| 433 | if group in completed_mutex_groups: |
| 434 | # If this is the action that completed the group, then there is no error |
| 435 | # since it's allowed to appear on the command line more than once. |
| 436 | completer_action = completed_mutex_groups[group] |
| 437 | if arg_action == completer_action: |
| 438 | return |
| 439 | |
| 440 | arg_str = f"{argparse._get_action_name(arg_action)}" |
| 441 | completer_str = f"{argparse._get_action_name(completer_action)}" |
| 442 | error = f"Error: argument {arg_str}: not allowed with argument {completer_str}" |
| 443 | raise CompletionError(error) |
| 444 | |
| 445 | # Mark that this action completed the group |
| 446 | completed_mutex_groups[group] = arg_action |
| 447 | |
| 448 | # Don't complete any of the other args in the group |
| 449 | for group_action in group._group_actions: |
| 450 | if group_action == arg_action: |
| 451 | continue |
| 452 | if group_action in self._flag_to_action.values(): |
| 453 | used_flags.update(group_action.option_strings) |
| 454 | elif group_action in remaining_positionals: |
| 455 | remaining_positionals.remove(group_action) |
| 456 | |
| 457 | # Arg can only be in one group, so we are done |
| 458 | break |
| 459 | |
| 460 | def _handle_last_token( |
| 461 | self, |
no test coverage detected