argcomplete
argcomplete copied to clipboard
zsh duplicates suggestions
This might be related to #504 but I think it is something else: when calling the script like this python ./foo.py
, I get duplicate suggestions. Of course it could also be an issue with zsh or my setup of it, so I hope other people can confirm it they also see this.
To reproduce
Test environment:
- Ubuntu 24.04
- Python 3.12.3
- argcomplete 3.1.4-1ubuntu0.1 (this is 3.1.4 with a patch back-ported from 3.3.0 to make it compatible with Python 12.3)
- zsh 5.9
I tested this with the following file foo.py
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OK
import argcomplete, argparse
parser = argparse.ArgumentParser()
argcomplete.autocomplete(parser)
./foo.py <TAB> # works fine
python foo.py <TAB> # works fine
python ./foo.py <TAB> # duplicate suggestions
Suggestions for the last option show up twice in the generated list:
--help
-h
-- show this help message and exit
--help
-h
-- show this help message and exit
Output with _ARC_DEBUG=1
The suggestions are generated once with WORDS: ['python', './foo.py']
and once with WORDS: ['./foo.py']
where in both cases, LINE: 'python ./foo.py '
.
python ./foo.py
word ./foo.py split, lexer state: ' '
In trailing whitespace
LINE: 'python ./foo.py '
POINT: 16
PREQUOTE: ''
PREFIX: ''
SUFFIX: ''
WORDS: ['python', './foo.py']
Active parsers: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
Visited positionals: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
invoking parser with ['./foo.py']
parsed args: (Namespace(), ['./foo.py'])
all active parsers: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
active_parser: MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
optional options: ['-h', '--help']
next_positional: None
Active actions (L=0): []
active options: ['-h', '--help']
display completions: {'-h': 'show this help message and exit', '--help': 'show this help message and exit'}
Returning completions: ['-h:show this help message and exit', '--help:show this help message and exit']
word ./foo.py split, lexer state: ' '
In trailing whitespace
LINE: 'python ./foo.py '
POINT: 16
PREQUOTE: ''
PREFIX: ''
SUFFIX: ''
WORDS: ['./foo.py']
Active parsers: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
Visited positionals: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
invoking parser with []
parsed args: (Namespace(), [])
all active parsers: [MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)]
active_parser: MonkeyPatchedIntrospectiveArgumentParser(prog='foo.py', usage=None, description=None, formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)
optional options: ['-h', '--help']
next_positional: None
Active actions (L=0): []
active options: ['-h', '--help']
display completions: {'-h': 'show this help message and exit', '--help': 'show this help message and exit'}
Returning completions: ['-h:show this help message and exit', '--help:show this help message and exit']