Skip to content
Myr

Update examples in docs, adds version update admonitions

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kevin Deldycke · committed by Kevin Deldycke · parent 78a4efc · Browse files · 4 files+25 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Refs: https://github.com/pallets/click/pull/3371#pullrequestreview-4173325028

Diff stats

4 files+25 added−6 removed

  • other:+25 added−6 removed

4 files+25 added−6 removed

modified:docs/parameter-types.md+21 added-2 removed
modified:docs/shell-completion.md+1 added-1 removed
118 unmodified lines
119120In this example, the type will suggest environment variables that start with the incomplete value.121122```python123class EnvVarType(ParamType):123class EnvVarType(ParamType[str]):124 name = "envvar"125126 def shell_complete(self, ctx, param, incomplete):127 return [
122 unmodified lines
modified:docs/support-multiple-versions.md+1 added-1 removed
53 unmodified lines
5455Here's an example ``ParamType`` subclass which uses this:5657```python58class CommaDelimitedString(click.ParamType):58class CommaDelimitedString(click.ParamType[str]):59 @add_ctx_arg60 def get_metavar(self, param: click.Parameter, ctx: click.Context | None) -> str:61 return "TEXT,TEXT,..."62```
modified:examples/validation/validation.py+2 added-2 removed
7 unmodified lines
8 raise click.BadParameter("Should be a positive, even integer.")9 return value101112class URL(click.ParamType):12class URL(click.ParamType[urlparse.ParseResult]):13 name = "url"1415 def convert(self, value, param, ctx):15 def convert(self, value, param, ctx) -> urlparse.ParseResult:16 if not isinstance(value, tuple):17 value = urlparse.urlparse(value)18 if value.scheme not in ("http", "https"):19 self.fail(
29 unmodified lines