Autocompletion bug with multiple hyphens in options #965
Replies: 5 comments 6 replies
-
@svlandeg @tiangolo this seems like a pretty clear bug, I took a look at the source code but didn't find any unit tests that trigger tab completion. If you can point me in the right direction I'll take a stab at fixing it |
Beta Was this translation helpful? Give feedback.
-
Hi @alexrosenfeld10, thanks for the report! You can find some autocompletion tests in |
Beta Was this translation helpful? Give feedback.
-
@tiangolo possible this could get looked at? It's a pretty common case to have hyphenated autocomplete suggestions, and this totally breaks that |
Beta Was this translation helpful? Give feedback.
-
@tiangolo would be great if we could get some eyes on this, having autocomplete is one of the main things typer writes about in the homepage. Again I'm happy to help if you can point me in the right direction |
Beta Was this translation helpful? Give feedback.
-
Hi @alexrosenfeld10, I've finally had some time to look at this in detail. Thanks for the detailed report and repo to reproduce. I've tried to write some unit tests to reproduce this issue, but I couldn't - they are all green on I've looked at the details of the examples you've provided. For instance:
and autocompleting with
leads to
Which seems wrong, as In this sense, I wonder whether maybe your title and focus on "two hyphens" is a red herring: I think what really matters here is that the beginning and end string are the same for two options. The same is true on your reproduction repo, where the options are
and the auto completion gives So, one question I have is this: what happens when you remove the hyphens from the strings, and have e.g. options
and autocomplete on
does it lead to
with Then one other question: what happens if you hit TAB twice and not just once? Do you see the full options as strings? Because on my system this does in fact work:
gives me as output:
i.e. the two correct options are given in full. This is also what we see in the succeeding unit tests of #1095. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
When the above code is run in a CLI and the input
my_cli test --name foo[TAB]
is entered into the shell (where[TAB]
indicates the user pressing tab to autocomplete the--name
argument), the following is the result of the autocompletion:I have observed similar behaviors in slightly different scenarios, for example, if the autocomplete function looks like this instead:
then a similar behavior happens when running
my_cli test --name [TAB]
:Note - if the autocompletion options only have one typo, instead of two or more, it works fine. As in, this has no issue:
Operating System
macOS
Operating System Details
No response
Typer Version
0.12.5
Python Version
3.12.3
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions