Skip to content

Commit 0ef6fb7

Browse files
chore: fix annotated typing
c
1 parent 31d0461 commit 0ef6fb7

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

cmd2/annotated.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def do_paint(
190190
Any,
191191
ClassVar,
192192
Literal,
193+
ParamSpec,
194+
Protocol,
193195
TypedDict,
194196
TypeVar,
195197
Union,
@@ -2117,8 +2119,18 @@ def handler(self_arg: Any, ns: Any) -> Any:
21172119
return handler, subcmd_name, parser_builder
21182120

21192121

2122+
_CommandParams = ParamSpec("_CommandParams")
2123+
_CommandReturn = TypeVar("_CommandReturn")
2124+
2125+
2126+
class _WithAnnotatedDecorator(Protocol):
2127+
"""The signature-preserving decorator ``with_annotated(...)`` returns (generic per call)."""
2128+
2129+
def __call__(self, fn: "Callable[_CommandParams, _CommandReturn]", /) -> "Callable[_CommandParams, _CommandReturn]": ...
2130+
2131+
21202132
@overload
2121-
def with_annotated(func: Callable[..., Any]) -> Callable[..., Any]: ...
2133+
def with_annotated(func: Callable[_CommandParams, _CommandReturn]) -> Callable[_CommandParams, _CommandReturn]: ...
21222134

21232135

21242136
@overload
@@ -2141,7 +2153,7 @@ def with_annotated(
21412153
subcommand_title: str | None = ...,
21422154
subcommand_description: str | None = ...,
21432155
**parser_kwargs: Unpack[Cmd2ParserKwargs],
2144-
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...
2156+
) -> _WithAnnotatedDecorator: ...
21452157

21462158

21472159
def with_annotated(

0 commit comments

Comments
 (0)