Skip to content

Commit 56b2ead

Browse files
authored
Expand args and kwargs for click_default_group methods (#13873)
1 parent 23c2cba commit 56b2ead

File tree

3 files changed

+64
-24
lines changed

3 files changed

+64
-24
lines changed

pyrightconfig.stricter.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"stubs/braintree",
3434
"stubs/caldav",
3535
"stubs/cffi",
36-
"stubs/click-default-group",
3736
"stubs/click-web",
3837
"stubs/corus",
3938
"stubs/dateparser",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version = "1.2.*"
2+
upstream_repository = "https://github.com/click-contrib/click-default-group"
23
# requires a version of click with a py.typed
34
requires = ["click>=8.0.0"]
4-
upstream_repository = "https://github.com/click-contrib/click-default-group"
Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,83 @@
1-
from _typeshed import Incomplete
2-
from collections.abc import Sequence
1+
from collections.abc import Callable, MutableMapping, Sequence
2+
from typing import Any, Final, Literal, overload
3+
from typing_extensions import deprecated
34

45
import click
56

67
__all__ = ["DefaultGroup"]
7-
__version__: str
8+
__version__: Final[str]
89

910
class DefaultGroup(click.Group):
1011
ignore_unknown_options: bool
1112
default_cmd_name: str | None
1213
default_if_no_args: bool
13-
def __init__(self, *args, **kwargs) -> None: ...
14+
# type hints were taken from click lib
15+
def __init__(
16+
self,
17+
name: str | None = None,
18+
commands: MutableMapping[str, click.Command] | Sequence[click.Command] | None = None,
19+
*,
20+
ignore_unknown_options: Literal[True] | None = True,
21+
default_cmd_name: str | None = None,
22+
default_if_no_args: bool = False,
23+
invoke_without_command: bool = False,
24+
no_args_is_help: bool | None = None,
25+
subcommand_metavar: str | None = None,
26+
chain: bool = False,
27+
result_callback: Callable[..., Any] | None = None, # Any is specified in click lib
28+
context_settings: MutableMapping[str, Any] | None = None, # Any is specified in click lib
29+
callback: Callable[..., Any] | None = None, # Any is specified in click lib
30+
params: list[click.Parameter] | None = None,
31+
help: str | None = None,
32+
epilog: str | None = None,
33+
short_help: str | None = None,
34+
options_metavar: str | None = "[OPTIONS]",
35+
add_help_option: bool = True,
36+
hidden: bool = False,
37+
deprecated: bool = False,
38+
) -> None: ...
1439
def set_default_command(self, command: click.Command) -> None: ...
1540
def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]: ...
1641
def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None: ...
1742
def resolve_command(self, ctx: click.Context, args: list[str]) -> tuple[str | None, click.Command | None, list[str]]: ...
1843
def format_commands(self, ctx: click.Context, formatter: click.HelpFormatter) -> None: ...
19-
def command(self, *args, **kwargs) -> click.Command: ... # incomplete
44+
@overload
45+
def command(
46+
self,
47+
__func: Callable[..., Any],
48+
/,
49+
*,
50+
name: str | None = ...,
51+
cls: type[click.Command] | None = ...,
52+
default: Literal[False] = False,
53+
) -> click.Command: ...
54+
@overload
55+
@deprecated("Use default param of `DefaultGroup` or `set_default_command()` instead")
56+
def command(
57+
self,
58+
__func: Callable[..., Any],
59+
/,
60+
*,
61+
name: str | None = ...,
62+
cls: type[click.Command] | None = ...,
63+
default: Literal[True],
64+
) -> click.Command: ...
65+
@overload
66+
def command(
67+
self, *, name: str | None = ..., cls: type[click.Command] | None = ..., default: Literal[False] = False
68+
) -> Callable[[Callable[..., Any]], click.Command]: ...
69+
@overload
70+
@deprecated("Use default param of `DefaultGroup` or `set_default_command()` instead")
71+
def command(
72+
self, *, name: str | None = ..., cls: type[click.Command] | None = ..., default: Literal[True]
73+
) -> Callable[[Callable[..., Any]], click.Command]: ...
74+
@overload
75+
def command(self, *args: Any, **kwargs: Any) -> Callable[[Callable[..., Any]], click.Command] | click.Command: ...
2076

2177
class DefaultCommandFormatter:
2278
group: click.Group
2379
formatter: click.HelpFormatter
2480
mark: str
25-
def __init__(self, group: click.Group, formatter: click.HelpFormatter, mark: str = ...) -> None: ...
81+
def __init__(self, group: click.Group, formatter: click.HelpFormatter, mark: str = "*") -> None: ...
2682
def write_dl(self, rows: Sequence[tuple[str, str]], col_max: int = 30, col_spacing: int = -2) -> None: ...
27-
def __getattr__(self, attr: str) -> Incomplete: ...
28-
# __getattr__ used to ala-derive from click.HelpFormatter:
29-
# indent_increment: int
30-
# width: int | None
31-
# current_indent: int
32-
# buffer: t.List[str]
33-
# def write(self, string: str) -> None: ...
34-
# def indent(self) -> None: ...
35-
# def dedent(self) -> None: ...
36-
# def write_usage(self, prog: str, args: str = ..., prefix: str | None = ...) -> None: ...
37-
# def write_heading(self, heading: str) -> None: ...
38-
# def write_paragraph(self) -> None: ...
39-
# def write_text(self, text: str) -> None: ...
40-
# def section(self, name: str) -> t.Iterator[None]: ...
41-
# def indentation(self) -> t.Iterator[None]: ...
42-
# def getvalue(self) -> str: ...
83+
def __getattr__(self, attr: str) -> Any: ... # attribute access is forwarded to click.HelpFormatter

0 commit comments

Comments
 (0)