|
151 | 151 | ]
|
152 | 152 |
|
153 | 153 | P = ParamSpec("P")
|
| 154 | +P2 = ParamSpec("P2") |
154 | 155 | R = t.TypeVar("R")
|
| 156 | +R2 = t.TypeVar("R2") |
155 | 157 | C = t.TypeVar("C", bound=BaseCommand)
|
156 | 158 |
|
157 | 159 | _CACHE_KEY = "_register_typer"
|
@@ -1171,6 +1173,16 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R:
|
1171 | 1173 | assert self.initializer
|
1172 | 1174 | return self.initializer(*args, **kwargs)
|
1173 | 1175 |
|
| 1176 | + @t.overload |
| 1177 | + def __get__( |
| 1178 | + self, obj: t.Union[None, t.Type["TyperCommand"]], owner: t.Any = None |
| 1179 | + ) -> "CommandGroup[P, R]": ... |
| 1180 | + |
| 1181 | + @t.overload |
| 1182 | + def __get__( |
| 1183 | + self, obj: "TyperCommand", owner: t.Any = None |
| 1184 | + ) -> t.Union[MethodType, t.Callable[P, R]]: ... |
| 1185 | + |
1174 | 1186 | def __get__(
|
1175 | 1187 | self, obj: t.Any, owner: t.Any = None
|
1176 | 1188 | ) -> t.Union["CommandGroup[P, R]", MethodType, t.Callable[P, R]]:
|
@@ -1347,7 +1359,7 @@ def command( # type: ignore
|
1347 | 1359 | # Rich settings
|
1348 | 1360 | rich_help_panel: t.Union[str, None] = Default(None),
|
1349 | 1361 | **kwargs,
|
1350 |
| - ) -> t.Callable[[t.Callable[P, R]], t.Callable[P, R]]: |
| 1362 | + ) -> t.Callable[[t.Callable[P2, R2]], t.Callable[P2, R2]]: |
1351 | 1363 | """
|
1352 | 1364 | A function decorator that creates a new command and attaches it to this group.
|
1353 | 1365 | This is a passthrough to Typer.command() and the options are the same, except
|
@@ -1418,7 +1430,7 @@ def command1(self):
|
1418 | 1430 | **kwargs,
|
1419 | 1431 | )
|
1420 | 1432 |
|
1421 |
| - def make_command(f: t.Callable[P, R]) -> t.Callable[P, R]: |
| 1433 | + def make_command(f: t.Callable[P2, R2]) -> t.Callable[P2, R2]: |
1422 | 1434 | owner = kwargs.pop("_owner", None)
|
1423 | 1435 | if owner:
|
1424 | 1436 | # attach this function to the adapted Command class
|
@@ -1464,7 +1476,7 @@ def group(
|
1464 | 1476 | # Rich settings
|
1465 | 1477 | rich_help_panel: t.Union[str, None] = Default(None),
|
1466 | 1478 | **kwargs,
|
1467 |
| - ) -> t.Callable[[t.Callable[P, R]], "CommandGroup[P, R]"]: |
| 1479 | + ) -> t.Callable[[t.Callable[P2, R2]], "CommandGroup[P2, R2]"]: |
1468 | 1480 | """
|
1469 | 1481 | Create a new subgroup and attach it to this group. This is like creating a new
|
1470 | 1482 | Typer app and adding it to a parent Typer app. The kwargs are passed through
|
@@ -1540,7 +1552,7 @@ def subcommand(self):
|
1540 | 1552 | )
|
1541 | 1553 | return grp
|
1542 | 1554 |
|
1543 |
| - def create_app(func: t.Callable[P, R]) -> CommandGroup[P, R]: |
| 1555 | + def create_app(func: t.Callable[P2, R2]) -> CommandGroup[P2, R2]: |
1544 | 1556 | owner = t.cast(t.Optional[t.Type[TyperCommand]], kwargs.pop("_owner", None))
|
1545 | 1557 | self.groups.append(
|
1546 | 1558 | CommandGroup( # pyright: ignore[reportArgumentType]
|
@@ -1597,7 +1609,7 @@ def initialize(
|
1597 | 1609 | # Rich settings
|
1598 | 1610 | rich_help_panel: t.Union[str, None] = Default(None),
|
1599 | 1611 | **kwargs,
|
1600 |
| -) -> t.Callable[[t.Callable[P, R]], t.Callable[P, R]]: |
| 1612 | +) -> t.Callable[[t.Callable[P2, R2]], t.Callable[P2, R2]]: |
1601 | 1613 | """
|
1602 | 1614 | A function decorator that creates a Typer_
|
1603 | 1615 | `callback <https://typer.tiangolo.com/tutorial/commands/callback/>`_. This
|
@@ -1690,7 +1702,7 @@ def divide(
|
1690 | 1702 | this can be used to group commands into panels in the help output.
|
1691 | 1703 | """
|
1692 | 1704 |
|
1693 |
| - def make_initializer(func: t.Callable[P, R]) -> t.Callable[P, R]: |
| 1705 | + def make_initializer(func: t.Callable[P2, R2]) -> t.Callable[P2, R2]: |
1694 | 1706 | _cache_initializer(
|
1695 | 1707 | func,
|
1696 | 1708 | common_init=True,
|
|
0 commit comments