|
55 | 55 | with_typehint, |
56 | 56 | ) |
57 | 57 |
|
58 | | -if sys.version_info < (3, 10): |
59 | | - from typing_extensions import Concatenate, ParamSpec |
60 | | -else: |
61 | | - from typing import Concatenate, ParamSpec |
62 | | - |
63 | | - |
64 | 58 | DEFAULT_MARKUP_MODE = getattr(typer.core, "DEFAULT_MARKUP_MODE", None) |
65 | 59 |
|
66 | 60 |
|
|
81 | 75 | "get_command", |
82 | 76 | ] |
83 | 77 |
|
84 | | -P = ParamSpec("P") |
85 | | -P2 = ParamSpec("P2") |
| 78 | +P = t.ParamSpec("P") |
| 79 | +P2 = t.ParamSpec("P2") |
86 | 80 | R = t.TypeVar("R") |
87 | 81 | R2 = t.TypeVar("R2") |
88 | 82 | C = t.TypeVar("C", bound=BaseCommand) |
|
91 | 85 | _CACHE_KEY = "_register_typer" |
92 | 86 |
|
93 | 87 |
|
94 | | -if sys.version_info < (3, 10): |
95 | | - # todo - remove this when support for <3.10 is dropped |
96 | | - class static_factory(type): |
97 | | - def __call__(self, *args, **kwargs): |
98 | | - assert args |
99 | | - if type(args[0]).__name__ == "staticmethod": |
100 | | - return args[0] |
101 | | - return super().__call__(*args, **kwargs) |
102 | | - |
103 | | - class staticmethod(t.Generic[P, R], metaclass=static_factory): |
104 | | - __func__: t.Callable[P, R] |
105 | | - |
106 | | - def __init__(self, func: t.Callable[P, R]): |
107 | | - self.__func__ = func |
108 | | - |
109 | | - def __getattr__(self, name): |
110 | | - return getattr(self.__func__, name) |
111 | | - |
112 | | - def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: |
113 | | - return self.__func__(*args, **kwargs) |
114 | | - |
115 | | - |
116 | 88 | @t.overload # pragma: no cover |
117 | 89 | def get_command( |
118 | 90 | command_name: str, |
@@ -940,7 +912,7 @@ def __init__( |
940 | 912 | result_callback: t.Optional[t.Callable[..., t.Any]] = Default(None), |
941 | 913 | # Command |
942 | 914 | context_settings: t.Optional[t.Dict[t.Any, t.Any]] = Default(None), |
943 | | - callback: t.Optional[t.Callable[Concatenate[TC, P], R]] = Default(None), |
| 915 | + callback: t.Optional[t.Callable[t.Concatenate[TC, P], R]] = Default(None), |
944 | 916 | help: t.Optional[t.Union[str, Promise]] = Default(None), |
945 | 917 | epilog: t.Optional[str] = Default(None), |
946 | 918 | short_help: t.Optional[t.Union[str, Promise]] = Default(None), |
@@ -1246,7 +1218,7 @@ def group( |
1246 | 1218 | ) -> t.Callable[ |
1247 | 1219 | [ |
1248 | 1220 | t.Callable[ |
1249 | | - Concatenate[TC, P2], R2 # pyright: ignore[reportInvalidTypeVarUse] |
| 1221 | + t.Concatenate[TC, P2], R2 # pyright: ignore[reportInvalidTypeVarUse] |
1250 | 1222 | ] |
1251 | 1223 | ], |
1252 | 1224 | "Typer[P2, R2]", |
@@ -1299,7 +1271,7 @@ def subcommand(self): |
1299 | 1271 | """ |
1300 | 1272 |
|
1301 | 1273 | def create_app( |
1302 | | - func: t.Callable[Concatenate[TC, P2], R2], |
| 1274 | + func: t.Callable[t.Concatenate[TC, P2], R2], |
1303 | 1275 | ) -> Typer[P2, R2]: |
1304 | 1276 | grp: Typer[P2, R2] = Typer( # pyright: ignore[reportAssignmentType] |
1305 | 1277 | name=name or _strip_static(func).__name__.replace("_", "-"), |
@@ -1697,7 +1669,7 @@ def group( |
1697 | 1669 | rich_help_panel: t.Union[str, None] = Default(None), |
1698 | 1670 | **kwargs: t.Any, |
1699 | 1671 | ) -> t.Callable[ |
1700 | | - [t.Callable[Concatenate[TC, P], R]], # pyright: ignore[reportInvalidTypeVarUse] |
| 1672 | + [t.Callable[t.Concatenate[TC, P], R]], # pyright: ignore[reportInvalidTypeVarUse] |
1701 | 1673 | Typer[P, R], |
1702 | 1674 | ]: |
1703 | 1675 | """ |
@@ -1766,7 +1738,7 @@ def subcommand(self): |
1766 | 1738 | """ |
1767 | 1739 |
|
1768 | 1740 | def create_app( |
1769 | | - func: t.Callable[Concatenate[TC, P], R], |
| 1741 | + func: t.Callable[t.Concatenate[TC, P], R], |
1770 | 1742 | ) -> Typer[P, R]: |
1771 | 1743 | grp = Typer( |
1772 | 1744 | name=name or _strip_static(func).__name__.replace("_", "-"), |
@@ -2951,7 +2923,7 @@ def group( |
2951 | 2923 | ) -> t.Callable[ |
2952 | 2924 | [ |
2953 | 2925 | t.Callable[ |
2954 | | - Concatenate[TC, P], R # pyright: ignore[reportInvalidTypeVarUse] |
| 2926 | + t.Concatenate[TC, P], R # pyright: ignore[reportInvalidTypeVarUse] |
2955 | 2927 | ] |
2956 | 2928 | ], |
2957 | 2929 | Typer[P, R], |
@@ -3023,7 +2995,7 @@ def grp_command(self, ...): |
3023 | 2995 | ) |
3024 | 2996 |
|
3025 | 2997 | def create_app( |
3026 | | - func: t.Callable[Concatenate[TC, P], R], |
| 2998 | + func: t.Callable[t.Concatenate[TC, P], R], |
3027 | 2999 | ) -> Typer[P, R]: |
3028 | 3000 | grp: Typer[P, R] = Typer( |
3029 | 3001 | name=name or func.__name__.replace("_", "-"), |
|
0 commit comments