File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import functools
4+ import typing as _t
5+
36import click
47
58from . import _parsed_param_types
69
10+ F = _t .TypeVar ("F" , bound = _t .Callable [..., _t .Any ])
11+
12+
13+ def _add_ctx_arg (f : F ) -> F :
14+ """
15+ Make ``ParamType`` methods compatible with various click versions, as documented
16+ in the click docs here:
17+ https://click.palletsprojects.com/en/stable/support-multiple-versions/
18+ """
19+
20+ @functools .wraps (f )
21+ def wrapper (* args : _t .Any , ** kwargs : _t .Any ) -> _t .Any :
22+ # NOTE: this check is skipped in coverage as it requires a lower `click` version
23+ # NOTE: once we have a coverage plugin for library version pragmas, we can make
24+ # NOTE: this do the appropriate dispatch
25+ if "ctx" not in kwargs : # pragma: no cover
26+ kwargs ["ctx" ] = click .get_current_context (silent = True )
27+
28+ return f (* args , ** kwargs )
29+
30+ return wrapper # type: ignore[return-value]
31+
732
833class DependencyGroupParamType (click .ParamType ):
9- def get_metavar (self , param : click .Parameter ) -> str :
34+ @_add_ctx_arg
35+ def get_metavar ( # type: ignore[override]
36+ self , param : click .Parameter , ctx : click .Context
37+ ) -> str :
1038 return "[pyproject-path:]groupname"
1139
1240 def convert (
You can’t perform that action at this time.
0 commit comments