Skip to content
Myr

Make `FuncParamType` is generic

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 3e2d92c · Browse files · 1 file+3 added−3 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#discussion_r3140255513

Diff stats

1 file+3 added−3 removed

  • other:+3 added−3 removed

1 file+3 added−3 removed

modified:src/click/types.py+3 added-3 removed
180 unmodified lines
181class FuncParamTypeInfoDict(ParamTypeInfoDict):182 func: t.Callable[[t.Any], t.Any]183184185class FuncParamType(ParamType[t.Any]):186 def __init__(self, func: t.Callable[[t.Any], t.Any]) -> None:185class FuncParamType(ParamType[ParamTypeValue]):186 def __init__(self, func: t.Callable[[t.Any], ParamTypeValue]) -> None:187 self.name: str = func.__name__188 self.func = func189190 def to_info_dict(self) -> FuncParamTypeInfoDict:191 return {"func": self.func, **super().to_info_dict()}192193 def convert(194 self, value: t.Any, param: Parameter | None, ctx: Context | None195 ) -> t.Any:195 ) -> ParamTypeValue:196 try:197 return self.func(value)198 except ValueError:199 try:
1058 unmodified lines