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

Returning zero completions leads to completer being called three times #523

Open
r4victor opened this issue Feb 14, 2025 · 3 comments
Open

Comments

@r4victor
Copy link

We're trying to use argcomplete to complete resource names. If we return an empty list, this causes completer to being called three times (tested on zsh). This is a problem since calling the completer involves a network request. Minimal example:

#!/usr/bin/env python
import argparse
import argcomplete
from argcomplete.completers import BaseCompleter


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("name").completer = NameCompleter()

    argcomplete.autocomplete(parser, always_complete_options=False)


class NameCompleter(BaseCompleter):

    def __call__(self, **kwargs):
        argcomplete.warn("Called completer")
        return []


main()

Then:

✗ eval "$(register-python-argcomplete clicomp.py)"
✗ ./clicomp.py <tab>
Called completer

Called completer

Called completer

I haven't found a logic in argcomplete that causes the repeated calls. Do you know if it's shell-related? What should a completer return in case of no completions to avoid repeated invocations? Thanks.

@kislyuk
Copy link
Owner

kislyuk commented Feb 17, 2025

Thank you for reporting this @r4victor. I agree the observed behavior is a concern and should not be expected.

@evanunderscore I think this is a side effect of #467 Never mind, something was wrong with my environment. I'm not sure what exactly causes this yet.

@r4victor
Copy link
Author

@kislyuk, thanks for looking into this!

We were testing it in fresh zsh environments and found that it only occurs with oh-my-zsh (dstackai/dstack#2285).

It'd be great if it's possible to fix this on the argcomplete side.

@solovyevt
Copy link

Great project, @kislyuk!

A more specific context for this issue: dstackai/dstack#2285 (comment)

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

3 participants