Skip to content

Commit

Permalink
Fix group overload (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Jul 18, 2023
2 parents 56b15be + 20280d4 commit 1a15373
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version 8.1.6

Unreleased

- Fix an issue with type hints for ``@click.group()``. :issue:`2558`


Version 8.1.5
-------------
Expand Down
8 changes: 2 additions & 6 deletions src/click/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
...
Expand Down
11 changes: 11 additions & 0 deletions tests/typing/typing_group_kw_options.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 1a15373

Please sign in to comment.