Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh duplicates suggestions #505

Open
FlorianPommerening opened this issue Sep 12, 2024 · 2 comments
Open

zsh duplicates suggestions #505

FlorianPommerening opened this issue Sep 12, 2024 · 2 comments

Comments

@FlorianPommerening
Copy link
Contributor

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']
@HarryZalessky
Copy link

HarryZalessky commented Jan 8, 2025

for me, this behaviour happens no matter how I'm calling the script, but only when I print a warn() message in my completer, and it prints the content 3 times. On zsh (5.8.1) on Ubuntu. Also, your reported behaviour happens as well

@FlorianPommerening
Copy link
Contributor Author

I think the part about warn() is unrelated because the demo program doesn't use any warnings. As far as I understand, this has to do with how zsh queries for suggestions. The warning somehow triggers a "follow-up" query. Maybe open a separate issue for it.

Thanks for checking that the behavior in my post occurs for you as well. From the debug output it seems like the first call, the one with WORDS: ['python', './foo.py'], should not be executed but instead be delegated to the second call (WORDS: ['./foo.py']).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants