Zsh (also?) recognize completion strings title:description with a : (colon). If a completed value is a string containing a colon, you get invalid completions.
I think the completion system was rewritten recently, and I didn't find anything in the most recent (unreleased) version that would fix that so it might be of some interest.
Here is a repro script, including a workaround by prefixing : with the escape \ character
#!/usr/bin/python
"""
Filename: repro
"""
from typing import List
import click
choices = {
"first": "The first one",
"sec:ond": "The second one",
}
def autocompletion_bug(ctx: click.Context, args: List[str], incomplete: str):
return [
(k, v) for k, v in choices.items() if incomplete in k
]
def autocompletion_workaround(ctx: click.Context, args: List[str], incomplete: str):
return [
(k.replace(":", "\:"), v) for k, v in choices.items() if incomplete in k
]
@click.command()
@click.argument("bug", nargs=1, autocompletion=autocompletion_bug)
@click.argument("correct", nargs=1, autocompletion=autocompletion_workaround)
def main(bug, correct):
pass
if __name__ == "__main__":
main()
The first argument puts part of the value sec:ond in the description
➜ repro <TAB><TAB>
first -- The first one
sec -- ond:The second one
The second argument implements a workaround
➜ repro first <TAB><TAB>
first -- The first one
sec:ond -- The second one
Environment:
- Python version: 3.9.2
- Click version: 7.1.2
- Zsh version: 5.8
Reference:
Zsh (also?) recognize completion strings
title:descriptionwith a:(colon). If a completed value is a string containing a colon, you get invalid completions.I think the completion system was rewritten recently, and I didn't find anything in the most recent (unreleased) version that would fix that so it might be of some interest.
Here is a repro script, including a workaround by prefixing
:with the escape\characterThe first argument puts part of the value
sec:ondin the descriptionThe second argument implements a workaround
Environment:
Reference: