Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- **complete_in_thread**: (boolean) if `True`, then completion will run in a separate
thread. If `False` then completion runs in the main thread and causes it to block if slow.
Defaults to `True`.

- Bug Fixes
- Fixed type hinting so that methods decorated with `with_annotated` no longer trigger spurious
mypy errors and preserve their original signature.

- Experimental features
- `@with_annotated` now supports `frozenset[T]` collection parameters, alongside the existing
`list[T]`, `set[T]`, and `tuple[T, ...]` collection types.
Expand Down
16 changes: 14 additions & 2 deletions cmd2/annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def do_paint(
Any,
ClassVar,
Literal,
ParamSpec,
Protocol,
TypedDict,
TypeVar,
Union,
Expand Down Expand Up @@ -2137,8 +2139,18 @@ def handler(self_arg: Any, ns: Any) -> Any:
return handler, subcmd_name, parser_builder


_CommandParams = ParamSpec("_CommandParams")
Comment thread
tleonhardt marked this conversation as resolved.
_CommandReturn = TypeVar("_CommandReturn")


class _WithAnnotatedDecorator(Protocol):
"""The signature-preserving decorator ``with_annotated(...)`` returns (generic per call)."""

def __call__(self, fn: Callable[_CommandParams, _CommandReturn], /) -> Callable[_CommandParams, _CommandReturn]: ...


@overload
def with_annotated(func: Callable[..., Any]) -> Callable[..., Any]: ...
def with_annotated(func: Callable[_CommandParams, _CommandReturn]) -> Callable[_CommandParams, _CommandReturn]: ...


@overload
Expand All @@ -2161,7 +2173,7 @@ def with_annotated(
subcommand_title: str | None = ...,
subcommand_description: str | None = ...,
**parser_kwargs: Unpack[Cmd2ParserKwargs],
) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...
) -> _WithAnnotatedDecorator: ...


def with_annotated(
Expand Down
Loading