Skip to content

Commit 1a15373

Browse files
authored
Fix group overload (#2565)
2 parents 56b15be + 20280d4 commit 1a15373

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Version 8.1.6
55

66
Unreleased
77

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

911
Version 8.1.5
1012
-------------

src/click/decorators.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,11 @@ def group(
271271

272272

273273
# variant: name omitted, cls _must_ be a keyword argument, @group(cmd=GroupCls, ...)
274-
# The _correct_ way to spell this overload is to use keyword-only argument syntax:
275-
# def group(*, cls: t.Type[GrpType], **attrs: t.Any) -> ...
276-
# However, mypy thinks this doesn't fit the overloaded function. Pyright does
277-
# accept that spelling, and the following work-around makes pyright issue a
278-
# warning that GrpType could be left unsolved, but mypy sees it as fine. *shrug*
279274
@t.overload
280275
def group(
281276
name: None = None,
282-
cls: t.Type[GrpType] = ...,
277+
*,
278+
cls: t.Type[GrpType],
283279
**attrs: t.Any,
284280
) -> t.Callable[[_AnyCallable], GrpType]:
285281
...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing_extensions import assert_type
2+
3+
import click
4+
5+
6+
@click.group(context_settings={})
7+
def hello() -> None:
8+
pass
9+
10+
11+
assert_type(hello, click.Group)

0 commit comments

Comments
 (0)