Skip to content

Static typing improvements in click.shell_completion#3460

Open
jorenham wants to merge 1 commit into
pallets:mainfrom
jorenham:typing/shell_completion/typed-dicts
Open

Static typing improvements in click.shell_completion#3460
jorenham wants to merge 1 commit into
pallets:mainfrom
jorenham:typing/shell_completion/typed-dicts

Conversation

@jorenham
Copy link
Copy Markdown
Contributor

@jorenham jorenham commented May 18, 2026

As promised in #3455, this improves several (static) types in click.shell_completion:

  • shell_complete narrowed return type
  • CompletionItem now has an optional (defaulting to Any for backcompat) generic type parameter for its .value. I did not update the other modules to use this type parameter to avoid merge conflicts, but because of the default=Any there's no downside to this.
  • ShellComplete.source_vars now returns a typed dict
  • add_completion_class is now parametrized on the cls instance type instead of the type type, so that it's easier to see by looking at the annotations that cls is supposed to be a type rather than an instance. If I remember correctly, now all type checkers support using it as class decorator otherwise, but don't quote me on this.
  • get_completion_class now has overloads for the builtin shell completion strings, so that get_completion_class("zsh") will now be inferred as type[ZshComplete] instead of type[ShellComplete] | None (the | None can be pretty annoying to deal with)

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

Successfully merging this pull request may close these issues.

1 participant