Closed
Labels
shell completionShell tab completionShell tab completion
Milestone
Description
Given foo containing:
#!/usr/bin/env python3
from click.shell_completion import CompletionItem
import click
class Foo(click.ParamType):
def convert(self, value, param, ctx):
return value
def shell_complete(self, ctx, param, incomplete):
return [
CompletionItem(value=value, help="adsf") for value in
["baz:quux", "spam:eggs"]
]
@click.command()
@click.argument("foo", type=Foo())
def main(foo):
print(foo)and running shell completion generation, followed by attempting to complete the command (indicated via <Tab>, produces:
⊙ PATH=$PWD:/Users/Julian/.local/share/virtualenvs/bowtie/bin/:$PATH
⊙ eval "$(_FOO_COMPLETE=zsh_source ./foo)"
⊙ foo <Tab>
baz -- quux:adsf
spam -- eggs:adsf
rather than the expected:
baz:quux -- adsf
spam:eggs -- adsf
This seems to be a regression on #1812.
The fix mentioned there (of "fake escaping" the colons via .replace(":", "\\:") seems to work.
Environment:
- Python version:
⊙ python --version julian@Airm
Python 3.11.9
- Click version:
⊙ python -m pip show click julian@Airm
Name: click
Version: 8.1.7
Summary: Composable command line interface toolkit
Home-page: https://palletsprojects.com/p/click/
Author:
Author-email:
License: BSD-3-Clause
Location: /Users/julian/.dotfiles/.local/share/virtualenvs/bowtie/lib/python3.11/site-packages
Requires:
Required-by: rich-click, trogon, virtue
Metadata
Metadata
Assignees
Labels
shell completionShell tab completionShell tab completion
Activity
[-]zsh completion still misbehaving in the presence of :[/-][+]zsh completion still misbehaving in the presence of `:`[/+]Add completion of Dialects.
the-13th-letter commentedon Jan 6, 2025
Are you suggesting that the application author should escape colons in the
CollectionItem's.valuefield themselves? That would affect completions of other shells as well (Bash, Fish), and it is specific to this single completion function, even though the “colon behavior” affects all Zsh completions.I would argue that the proper place to fix this is in the
click.shell_complete.ZshComplete.format_completionsmethod, which specifically serializes data to be passed to the Zsh completion machinery. This is a serialization failure at its core, and that is the function that is supposedly responsible for that task....or at least, that is how I intend to fix this, for my
click-powered applications, in a subclass that replacesclick's stockZshCompleteclass.That said, I would very much appreciate a
clickcore developer chiming in here on how to submit a PR for this, specifically how to write tests thatclickis interacting properly with external, non-Python components such as Zsh. Or are we satisfied with testing that the serialization output is “as expected”?Julian commentedon Jan 6, 2025
No I was reporting that I thought application authors shouldn't have to do so, but I didn't really consider what implementation detail I hoped would change (so honestly I have no opinion there).
Consolidate shell completion, add tests and fix Zsh output
Fix Zsh completion output, again