2121R = t .TypeVar ("R" )
2222T = t .TypeVar ("T" )
2323_AnyCallable = t .Callable [..., t .Any ]
24- _Decorator : "te.TypeAlias" = t .Callable [[T ], T ]
2524FC = t .TypeVar ("FC" , bound = t .Union [_AnyCallable , Command ])
2625
2726
@@ -150,16 +149,12 @@ def command(
150149 ...
151150
152151
153- # variant: name omitted, cls _must_ be a keyword argument, @command(cmd=CommandCls, ...)
154- # The correct way to spell this overload is to use keyword-only argument syntax:
155- # def command(*, cls: t.Type[CmdType], **attrs: t.Any) -> ...
156- # However, mypy thinks this doesn't fit the overloaded function. Pyright does
157- # accept that spelling, and the following work-around makes pyright issue a
158- # warning that CmdType could be left unsolved, but mypy sees it as fine. *shrug*
152+ # variant: name omitted, cls _must_ be a keyword argument, @command(cls=CommandCls, ...)
159153@t .overload
160154def command (
161155 name : None = None ,
162- cls : t .Type [CmdType ] = ...,
156+ * ,
157+ cls : t .Type [CmdType ],
163158 ** attrs : t .Any ,
164159) -> t .Callable [[_AnyCallable ], CmdType ]:
165160 ...
@@ -331,7 +326,7 @@ def _param_memo(f: t.Callable[..., t.Any], param: Parameter) -> None:
331326
332327def argument (
333328 * param_decls : str , cls : t .Optional [t .Type [Argument ]] = None , ** attrs : t .Any
334- ) -> _Decorator [ FC ]:
329+ ) -> t . Callable [[ FC ], FC ]:
335330 """Attaches an argument to the command. All positional arguments are
336331 passed as parameter declarations to :class:`Argument`; all keyword
337332 arguments are forwarded unchanged (except ``cls``).
@@ -359,7 +354,7 @@ def decorator(f: FC) -> FC:
359354
360355def option (
361356 * param_decls : str , cls : t .Optional [t .Type [Option ]] = None , ** attrs : t .Any
362- ) -> _Decorator [ FC ]:
357+ ) -> t . Callable [[ FC ], FC ]:
363358 """Attaches an option to the command. All positional arguments are
364359 passed as parameter declarations to :class:`Option`; all keyword
365360 arguments are forwarded unchanged (except ``cls``).
@@ -385,7 +380,7 @@ def decorator(f: FC) -> FC:
385380 return decorator
386381
387382
388- def confirmation_option (* param_decls : str , ** kwargs : t .Any ) -> _Decorator [ FC ]:
383+ def confirmation_option (* param_decls : str , ** kwargs : t .Any ) -> t . Callable [[ FC ], FC ]:
389384 """Add a ``--yes`` option which shows a prompt before continuing if
390385 not passed. If the prompt is declined, the program will exit.
391386
@@ -409,7 +404,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
409404 return option (* param_decls , ** kwargs )
410405
411406
412- def password_option (* param_decls : str , ** kwargs : t .Any ) -> _Decorator [ FC ]:
407+ def password_option (* param_decls : str , ** kwargs : t .Any ) -> t . Callable [[ FC ], FC ]:
413408 """Add a ``--password`` option which prompts for a password, hiding
414409 input and asking to enter the value again for confirmation.
415410
@@ -433,7 +428,7 @@ def version_option(
433428 prog_name : t .Optional [str ] = None ,
434429 message : t .Optional [str ] = None ,
435430 ** kwargs : t .Any ,
436- ) -> _Decorator [ FC ]:
431+ ) -> t . Callable [[ FC ], FC ]:
437432 """Add a ``--version`` option which immediately prints the version
438433 number and exits the program.
439434
@@ -539,7 +534,7 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
539534 return option (* param_decls , ** kwargs )
540535
541536
542- def help_option (* param_decls : str , ** kwargs : t .Any ) -> _Decorator [ FC ]:
537+ def help_option (* param_decls : str , ** kwargs : t .Any ) -> t . Callable [[ FC ], FC ]:
543538 """Add a ``--help`` option which immediately prints the help page
544539 and exits the program.
545540
0 commit comments