Skip to content
Myr

correctly annotate return type of @command(cls=XYZ)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by matejcik · committed by matejcik · parent d14ee19 · Browse files · 2 files+25 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+25 added−4 removed

  • other:+25 added−4 removed

2 files+25 added−4 removed

modified:src/click/decorators.py+23 added-4 removed
119 unmodified lines
120 )121 return decorator122123124CmdType = t.TypeVar("CmdType", bound=Command)125126127@t.overload128def command(129 name: t.Optional[str] = None,127 cls: t.Optional[t.Type[Command]] = None,130 cls: t.Type[CmdType] = ...,131 **attrs: t.Any,129) -> t.Callable[[F], Command]:132) -> t.Callable[..., CmdType]:133 ...134135136@t.overload137def command(138 name: t.Optional[str] = None,139 **attrs: t.Any,140) -> t.Callable[..., Command]:141 ...142143144@t.overload145def command(146 name: t.Callable,136 cls: t.Optional[t.Type[Command]] = None,147 cls: t.Type[CmdType] = ...,148 **attrs: t.Any,149) -> CmdType:150 ...151152153@t.overload154def command(155 name: t.Callable,156 **attrs: t.Any,157) -> Command:158 ...159160161def command(162 name: t.Union[str, t.Callable, None] = None,163 cls: t.Optional[t.Type[Command]] = None,164 **attrs: t.Any,146) -> t.Union[Command, t.Callable[[F], Command]]:165) -> t.Union[Command, t.Callable[..., Command]]:166 r"""Creates a new :class:`Command` and uses the decorated function as167 callback. This will also automatically attach all decorated168 :func:`option`\s and :func:`argument`\s as parameters to the command.169
336 unmodified lines
modified:CHANGES.rst+2 added
41 unmodified lines
42 pattern. :issue:`2195`43- It's possible to pass a list of ``params`` to ``@command``. Any44 params defined with decorators are appended to the passed params.45 :issue:`2131`.46- ``@command`` decorator is annotated as returning the correct type if47 a ``cls`` argument is used. :issue:`2211`484950Version 8.0.451-------------
948 unmodified lines