Skip to content

Commit 705f2ba

Browse files
committed
Re-ordered some code so that quotes are not needed around type annotations
1 parent 77cd8ee commit 705f2ba

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

‎cmd2/annotated.py‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,13 +2876,32 @@ def parser_builder() -> Cmd2ArgumentParser:
28762876
return parser_builder
28772877

28782878

2879+
_CommandParams = ParamSpec("_CommandParams")
2880+
_DecoratorParams = ParamSpec("_DecoratorParams")
2881+
2882+
2883+
class _AnnotatedCommand(Protocol[_CommandParams]):
2884+
"""A callable command method with the metadata used by ``with_annotated``."""
2885+
2886+
__name__: str
2887+
__qualname__: str
2888+
2889+
def __call__(self, *args: _CommandParams.args, **kwargs: _CommandParams.kwargs) -> bool | None: ...
2890+
2891+
2892+
class _WithAnnotatedDecorator(Protocol):
2893+
"""The signature-preserving decorator ``with_annotated(...)`` returns (generic per call)."""
2894+
2895+
def __call__(self, fn: _AnnotatedCommand[_CommandParams], /) -> _AnnotatedCommand[_CommandParams]: ...
2896+
2897+
28792898
def _build_subcommand_handler(
2880-
func: "_AnnotatedCommand[_CommandParams]",
2899+
func: _AnnotatedCommand[_CommandParams],
28812900
subcommand_to: str,
28822901
*,
28832902
base_command: bool = False,
28842903
options: _ParserBuildOptions,
2885-
) -> tuple["_AnnotatedCommand[_CommandParams]", str, Callable[[], Cmd2ArgumentParser]]:
2904+
) -> tuple[_AnnotatedCommand[_CommandParams], str, Callable[[], Cmd2ArgumentParser]]:
28862905
"""Build a subcommand's parser and a handler that unpacks the Namespace into typed kwargs.
28872906
28882907
:param func: the subcommand handler function
@@ -2933,25 +2952,6 @@ def handler(*args: _CommandParams.args, **kwargs: _CommandParams.kwargs) -> bool
29332952
return handler, subcmd_name, parser_builder
29342953

29352954

2936-
_CommandParams = ParamSpec("_CommandParams")
2937-
_DecoratorParams = ParamSpec("_DecoratorParams")
2938-
2939-
2940-
class _AnnotatedCommand(Protocol[_CommandParams]):
2941-
"""A callable command method with the metadata used by ``with_annotated``."""
2942-
2943-
__name__: str
2944-
__qualname__: str
2945-
2946-
def __call__(self, *args: _CommandParams.args, **kwargs: _CommandParams.kwargs) -> bool | None: ...
2947-
2948-
2949-
class _WithAnnotatedDecorator(Protocol):
2950-
"""The signature-preserving decorator ``with_annotated(...)`` returns (generic per call)."""
2951-
2952-
def __call__(self, fn: _AnnotatedCommand[_CommandParams], /) -> _AnnotatedCommand[_CommandParams]: ...
2953-
2954-
29552955
@overload
29562956
def with_annotated(func: _AnnotatedCommand[_CommandParams], /) -> _AnnotatedCommand[_CommandParams]: ...
29572957

0 commit comments

Comments
 (0)