Skip to content

Commit 383c04e

Browse files
committed
Fix types in annotated.py so both mypy and ty pass
1 parent 976f47d commit 383c04e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎cmd2/annotated.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def do_build(self, target: str, common: CommonArgs):
290290
TypeVar,
291291
Union,
292292
Unpack,
293+
cast,
293294
get_args,
294295
get_origin,
295296
get_type_hints,
@@ -3052,7 +3053,7 @@ def with_annotated(
30523053

30533054
def decorator(
30543055
command_func: _AnnotatedCommand[_CommandParams],
3055-
) -> _CommandFunc:
3056+
) -> _AnnotatedCommand[_CommandParams]:
30563057
if with_unknown_args:
30573058
unknown_param = inspect.signature(command_func).parameters.get("_unknown")
30583059
if unknown_param is None:
@@ -3082,7 +3083,7 @@ def decorator(
30823083
parser_source=subcmd_parser_builder,
30833084
)
30843085
setattr(handler, constants.SUBCOMMAND_ATTR_SPEC, subcommand_spec)
3085-
return handler
3086+
return cast(_AnnotatedCommand[_CommandParams], handler)
30863087

30873088
command_name = command_func.__name__[len(constants.COMMAND_FUNC_PREFIX) :]
30883089

@@ -3164,4 +3165,4 @@ def cmd_wrapper(*args: Any, **kwargs: Any) -> bool | None:
31643165
# Support both @with_annotated and @with_annotated(...)
31653166
if func is not None:
31663167
return decorator(func)
3167-
return decorator
3168+
return cast(_WithAnnotatedDecorator, decorator)

0 commit comments

Comments
 (0)