Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Fix attached-value dispatch so exclusive completion supports valid attached values.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds completion for values attached to unquoted short-option clusters while preserving argparse precedence and context.
Changes:
- Implements attached-value parsing and reconstructed completion prefixes.
- Handles nargs, conflicts, subparsers, custom completers, and safety rules.
- Adds regression coverage for clustered options and edge cases.
File summaries
| File | Summary |
|---|---|
test/test.py |
Adds regression tests for attached values and clusters. |
argcomplete/finders.py |
Implements attached-option completion. A moderate issue remains: ExclusiveCompletionFinder rejects attached actions for inputs such as -oo at lines 437 and 445. |
Review details
Suppressed comments (1)
argcomplete/finders.py:448
- The parser has already executed each safe leading action while parsing this token (the introspection hook calls
_orig_callableforsafe_actionsbefore the attached value is completed). Replaying them here increments or appends their state a second time; for example,-bvvooleavesparsed_args.v == 2after parsing but this loop changes the copied namespace to4, so the new cluster-context test fails. Keep the copied namespace, but do not invoke the leading actions again.
parsed_args = argparse.Namespace(**vars(parsed_args))
for action, option_string in leading_options:
if action._orig_class in safe_actions:
action._orig_callable(parser, parsed_args, [], option_string=option_string)
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| attached_action, optional_prefix, cword_prefix, leading_options = attached | ||
| seen_actions = set() | ||
| for action in [item[0] for item in leading_options] + [attached_action]: | ||
| if not self._action_allowed(action, parser) or any( |
|
Thanks for calling out the ExclusiveCompletionFinder interaction. The first-use There was a related gap when an option had appeared in an earlier word: The count replay should remain: switches in the current word have not been parsed. Protocol tests confirm Validation: 13 targeted unittest methods passed on Python 3.14, plus Ruff lint/format checks. This revision was tested through the completion protocol, without a full suite run or interactive shell Tab test. |
Related #563.
Unquoted attached values such as
-ooand-boocurrently return no completions for-owith choicesone,two, andthree. This change resolves the current word using argparse's option lookup, walks valid leading switches, and completes the value with its original option prefix (-ooneor-boone). It also handles a cluster ending in a value-taking option, such as-bo.Exact option names and ambiguous abbreviations retain argparse's precedence. The lookup respects nargs and mutual exclusion; leading switches contribute to the completer's local namespace only when their action class is already in
safe_actions. Custom value completers receive the value prefix, and completion descriptions retain the reconstructed option prefix.This is a partial fix: completion inside an unclosed quote, including the quoted examples in #563, remains on the existing path. Shell replacement boundaries for those examples are not addressed here.
Initial revision validation on Windows with Python 3.12.14 and 3.14.4:
bashselects an unavailable Windows launcher. The wrapper is not part of this patch. Real interactive Bash/Zsh/pexpect Tab insertion and the Linux/macOS CI matrix have not been validated locally.Review revision: attached values now also complete when ExclusiveCompletionFinder has already seen the option in an earlier word. The change retains custom finder constraints, mutual exclusion, and the current cluster's count context. Thirteen targeted unittest methods pass on Python 3.14, with Ruff lint/format checks passing. This revision was not rerun through the full suite or an interactive shell Tab test; the initial validation and limitations above remain historical results for the initial revision.