GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix Zsh completions with colons by the-13th-letter · Pull Request #2846 · pallets/click

Conversation

@the-13th-letter

@the-13th-letter the-13th-letter commented Jan 17, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The Zsh completion script uses different primitives to load completion items into Zsh depending on whether a completion item has a description or not.

  • For items with descriptions, the Zsh _describe function is used, which expects item plus description pairs as values, separated by a colon. In turn, any colon within the item must be escaped.
  • For items without descriptions, the Zsh compadd builtin is used, which expects literal items, without escaping. Actually escaping colons in the item will corrupt the item.

click's built-in Zsh completion class does not escape colons in the item. So it only handles the second case correctly, not the first; see e.g. #2703. This PR fixes this by choosing a suitable serialization, for each item separately, according to the abovementioned escaping requirements.

Since at its core this is an issue of two systems not agreeing on the format for exchanging data, and since we principally control both systems, we could fix this on either side. However, because the Zsh completion script is typically already installed in the user's shell, which is both harder to detect within click and harder to change or influence, we opt to change the click side instead, even if it the serialization needs to be more irregular.

Resolves #2703


  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
    • “docs“ presumably not applicable in this case?
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
    • Not applicable in this case?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Rowlando13
Rowlando13 requested a review from AndreasBackx January 21, 2025 03:24
@Rowlando13

Rowlando13 commented Jan 21, 2025

Copy link
Copy Markdown
Member

Thanks for taking the time to submit this PR. We will review this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@the-13th-letter
the-13th-letter changed the base branch from release-8.2.0 to main March 20, 2025 17:46
@the-13th-letter

the-13th-letter commented Mar 20, 2025

Copy link
Copy Markdown
Contributor Author

Rebased onto and retargeted to main, since release-8.2.0 looks pretty dead to me. I used this opportunity to also add some TLDR-style inline commentary to the patch, and fix some other commentary typos.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Rowlando13 Rowlando13 added this to the 8.2.1 milestone May 10, 2025
@davidism davidism modified the milestones: 8.2.1, 8.2.2 May 14, 2025
@AndreasBackx

AndreasBackx commented May 14, 2025

Copy link
Copy Markdown
Collaborator

Apologies for the delay. This looks pretty good, but it's a bit hard to review. We'd ideally need some way to create tests for autocomplete. Does anyone know how we could possibly trigger autocomplete? If so, we might be able to use scrut to create a test for it.

I think it should be fine with just a note in the changes and if that's done, we can merge this afaik.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AndreasBackx AndreasBackx mentioned this pull request May 14, 2025
Add e2e completion testing #2917
Open
AndreasBackx
AndreasBackx approved these changes May 14, 2025
View reviewed changes

@AndreasBackx AndreasBackx left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment, a nitpick and otherwise just CHANGES that needs an addition.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/click/shell_completion.py Outdated
Comment on lines +375 to +389
""""""
# See issue #1812 and issue #2703 for further context. (TL;DR:
# colons sometimes need special handling.)
#
# Items *with* help are registered with zsh's `_describe`, which
# splits off the help/description after the first colon. So
# escape all colons in item.value so that they arrive intact.
#
# Items *without* help are registered with zsh's `compadd`,
# which does no colon handling. So do *not* escape colons in
# item.value, lest the completions themselves ultimately get
# mangled.
#
# Finally, there is no functional difference between using an
# empty help and using "_" as help.

@AndreasBackx AndreasBackx May 14, 2025

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean this up a tad perhaps? It'd be nice to have this explained in-line if possible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@the-13th-letter the-13th-letter May 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commentary rewritten in the current iteration of this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
AndreasBackx
AndreasBackx requested changes May 14, 2025
View reviewed changes

@AndreasBackx AndreasBackx left a comment

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meant to click request changes, woopsie!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-13th-letter
the-13th-letter requested a review from AndreasBackx May 18, 2025 16:10
@the-13th-letter

the-13th-letter commented May 18, 2025

Copy link
Copy Markdown
Contributor Author

Rebased onto stable as of today, and attempted to clean up the inline commentary as requested.

Apologies for the delay. This looks pretty good, but it's a bit hard to review. We'd ideally need some way to create tests for autocomplete. Does anyone know how we could possibly trigger autocomplete? If so, we might be able to use scrut to create a test for it.

Can't help you there, sorry. To test my submission, I did write a small < 50-line click application that completed filenames manually, sometimes adding help texts, sometimes even with colons, and then interactively tab-completed arguments in a zsh session, in a directory with specially-prepared filenames. This isn't very generalizable to other test uses, and the triggering of tab completion was still manual.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@davidism
davidism changed the base branch from main to stable May 18, 2025 16:46
@Rowlando13
Rowlando13 deleted the branch pallets:stable July 16, 2025 06:23
@Rowlando13 Rowlando13 closed this Jul 16, 2025
@Rowlando13 Rowlando13 reopened this Jul 16, 2025
@Rowlando13 Rowlando13 modified the milestones: 8.2.2, 8.2.3 Jul 16, 2025
the-13th-letter and others added 2 commits July 21, 2025 20:24
@the-13th-letter @AndreasBackx
Fix Zsh completion items containing colons (#2703)
22718de
@AndreasBackx
Remove hardcoded zsh template assertion in test.
9e30175
@AndreasBackx

AndreasBackx commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

I've rebased this on stable. Then I've removed the ZSH template check, I'm not sure why we're checking the output of the ZSH completion here. We only really care about the output, don't we? Let me know in case I missed something. Otherwise this seems good to land if CI is good.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AndreasBackx
AndreasBackx approved these changes Jul 21, 2025
View reviewed changes
@AndreasBackx
AndreasBackx merged commit a1235aa into pallets:stable Jul 21, 2025
@Rowlando13 Rowlando13 modified the milestones: 8.2.3, 8.2.2 Jul 22, 2025
@kdeldycke kdeldycke added bug shell completion Shell tab completion labels Jul 22, 2025
Rowlando13 pushed a commit to Rowlando13/click that referenced this pull request Jul 30, 2025
@the-13th-letter @AndreasBackx @Rowlando13
Fix Zsh completions with colons (pallets#2846)
d9e97b1
Resolves pallets#2846.

Co-authored-by: Andreas Backx <[email protected]>
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 6, 2025
@the-13th-letter
the-13th-letter deleted the fix-zsh-completion-colon-escaping branch August 28, 2025 20:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@AndreasBackx AndreasBackx AndreasBackx approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

shell completion Shell tab completion

Projects

None yet

Milestone

8.2.2

Development

Successfully merging this pull request may close these issues.

zsh completion still misbehaving in the presence of :

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@the-13th-letter @Rowlando13 @AndreasBackx @kdeldycke @davidism
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.