-
Notifications
You must be signed in to change notification settings - Fork 132
fix: fix annotated typing #1692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,6 +198,8 @@ def do_paint( | |
| Any, | ||
| ClassVar, | ||
| Literal, | ||
| ParamSpec, | ||
| Protocol, | ||
| TypedDict, | ||
| TypeVar, | ||
| Union, | ||
|
|
@@ -2136,8 +2138,18 @@ def handler(self_arg: Any, ns: Any) -> Any: | |
| return handler, subcmd_name, parser_builder | ||
|
|
||
|
|
||
| _CommandParams = ParamSpec("_CommandParams") | ||
| _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]": ... | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary string annotations for Callable can cause type variable binding issues. Since Recommend: 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 | ||
|
|
@@ -2160,7 +2172,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( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend adding a brief bug fix blurb to the
CHANGELOG.mdfile about fixing type hinting for this stuff.