diff --git a/CHANGES.rst b/CHANGES.rst index fe74e5e39..57d95c547 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ Version 8.1.6 Unreleased +- Fix an issue with type hints for ``@click.group()``. :issue:`2558` + Version 8.1.5 ------------- diff --git a/src/click/decorators.py b/src/click/decorators.py index 674aee53b..d9bba9502 100644 --- a/src/click/decorators.py +++ b/src/click/decorators.py @@ -271,15 +271,11 @@ def group( # variant: name omitted, cls _must_ be a keyword argument, @group(cmd=GroupCls, ...) -# The _correct_ way to spell this overload is to use keyword-only argument syntax: -# def group(*, cls: t.Type[GrpType], **attrs: t.Any) -> ... -# However, mypy thinks this doesn't fit the overloaded function. Pyright does -# accept that spelling, and the following work-around makes pyright issue a -# warning that GrpType could be left unsolved, but mypy sees it as fine. *shrug* @t.overload def group( name: None = None, - cls: t.Type[GrpType] = ..., + *, + cls: t.Type[GrpType], **attrs: t.Any, ) -> t.Callable[[_AnyCallable], GrpType]: ... diff --git a/tests/typing/typing_group_kw_options.py b/tests/typing/typing_group_kw_options.py new file mode 100644 index 000000000..579132fac --- /dev/null +++ b/tests/typing/typing_group_kw_options.py @@ -0,0 +1,11 @@ +from typing_extensions import assert_type + +import click + + +@click.group(context_settings={}) +def hello() -> None: + pass + + +assert_type(hello, click.Group)