|
8 | 8 | overload,
|
9 | 9 | cast,
|
10 | 10 | Optional,
|
11 |
| - Dict, |
| 11 | + Mapping, |
12 | 12 | )
|
13 |
| -from typing_extensions import Protocol, TypedDict, Unpack, Literal |
14 |
| - |
15 | 13 |
|
16 | 14 | if TYPE_CHECKING:
|
17 | 15 | from invoke.runners import Promise, Result
|
18 | 16 | from invoke.watchers import StreamWatcher
|
19 | 17 |
|
| 18 | + from typing_extensions import Protocol, TypedDict, Unpack, Literal |
| 19 | + |
| 20 | + class _BaseRunParams(TypedDict, total=False): |
| 21 | + dry: bool |
| 22 | + echo: bool |
| 23 | + echo_format: str |
| 24 | + echo_stdin: Optional[bool] |
| 25 | + encoding: Optional[str] |
| 26 | + err_stream: IO |
| 27 | + env: Mapping[str, str] |
| 28 | + fallback: bool |
| 29 | + hide: Optional[bool] |
| 30 | + in_stream: Optional[IO] |
| 31 | + out_stream: IO |
| 32 | + pty: bool |
| 33 | + replace_env: bool |
| 34 | + shell: str |
| 35 | + timeout: Optional[int] |
| 36 | + warn: bool |
| 37 | + watchers: Sequence["StreamWatcher"] |
| 38 | + |
| 39 | + class RunParams(_BaseRunParams, total=False): |
| 40 | + """Parameters for Runner.run""" |
| 41 | + |
| 42 | + asynchronous: bool |
| 43 | + disown: bool |
| 44 | + |
| 45 | + class RunFunction(Protocol): |
| 46 | + """A function that runs a command.""" |
| 47 | + |
| 48 | + @overload |
| 49 | + def __call__( |
| 50 | + self, |
| 51 | + command: str, |
| 52 | + *, |
| 53 | + disown: Literal[True], |
| 54 | + **kwargs: Unpack[_BaseRunParams], |
| 55 | + ) -> None: |
| 56 | + ... |
| 57 | + |
| 58 | + @overload |
| 59 | + def __call__( |
| 60 | + self, |
| 61 | + command: str, |
| 62 | + *, |
| 63 | + disown: bool, |
| 64 | + **kwargs: Unpack[_BaseRunParams], |
| 65 | + ) -> Optional["Result"]: |
| 66 | + ... |
| 67 | + |
| 68 | + @overload |
| 69 | + def __call__( |
| 70 | + self, |
| 71 | + command: str, |
| 72 | + *, |
| 73 | + asynchronous: Literal[True], |
| 74 | + **kwargs: Unpack[_BaseRunParams], |
| 75 | + ) -> "Promise": |
| 76 | + ... |
| 77 | + |
| 78 | + @overload |
| 79 | + def __call__( |
| 80 | + self, |
| 81 | + command: str, |
| 82 | + *, |
| 83 | + asynchronous: bool, |
| 84 | + **kwargs: Unpack[_BaseRunParams], |
| 85 | + ) -> Union["Promise", "Result"]: |
| 86 | + ... |
| 87 | + |
| 88 | + @overload |
| 89 | + def __call__( |
| 90 | + self, |
| 91 | + command: str, |
| 92 | + **kwargs: Unpack[_BaseRunParams], |
| 93 | + ) -> "Result": |
| 94 | + ... |
| 95 | + |
| 96 | + def __call__( |
| 97 | + self, |
| 98 | + command: str, |
| 99 | + **kwargs: Unpack[RunParams], |
| 100 | + ) -> Optional["Result"]: |
| 101 | + ... |
| 102 | + |
20 | 103 |
|
21 | 104 | def annotate_run_function(func: Callable[..., Any]) -> "RunFunction":
|
22 | 105 | """Add standard run function annotations to a function."""
|
23 |
| - return cast(RunFunction, func) |
24 |
| - |
25 |
| - |
26 |
| -class _BaseRunParams(TypedDict, total=False): |
27 |
| - dry: bool |
28 |
| - echo: bool |
29 |
| - echo_format: str |
30 |
| - echo_stdin: Optional[bool] |
31 |
| - encoding: Optional[str] |
32 |
| - err_stream: IO |
33 |
| - env: Dict[str, str] |
34 |
| - fallback: bool |
35 |
| - hide: Optional[bool] |
36 |
| - in_stream: Optional[IO] |
37 |
| - out_stream: IO |
38 |
| - pty: bool |
39 |
| - replace_env: bool |
40 |
| - shell: str |
41 |
| - timeout: Optional[int] |
42 |
| - warn: bool |
43 |
| - watchers: Sequence["StreamWatcher"] |
44 |
| - |
45 |
| - |
46 |
| -class RunParams(_BaseRunParams, total=False): |
47 |
| - """Parameters for Runner.run""" |
48 |
| - |
49 |
| - asynchronous: bool |
50 |
| - disown: bool |
51 |
| - |
52 |
| - |
53 |
| -class RunFunction(Protocol): |
54 |
| - """A function that runs a command.""" |
55 |
| - |
56 |
| - @overload |
57 |
| - def __call__( |
58 |
| - self, |
59 |
| - command: str, |
60 |
| - *, |
61 |
| - disown: Literal[True], |
62 |
| - **kwargs: Unpack[_BaseRunParams], |
63 |
| - ) -> None: |
64 |
| - ... |
65 |
| - |
66 |
| - @overload |
67 |
| - def __call__( |
68 |
| - self, |
69 |
| - command: str, |
70 |
| - *, |
71 |
| - disown: bool, |
72 |
| - **kwargs: Unpack[_BaseRunParams], |
73 |
| - ) -> Optional["Result"]: |
74 |
| - ... |
75 |
| - |
76 |
| - @overload |
77 |
| - def __call__( |
78 |
| - self, |
79 |
| - command: str, |
80 |
| - *, |
81 |
| - asynchronous: Literal[True], |
82 |
| - **kwargs: Unpack[_BaseRunParams], |
83 |
| - ) -> "Promise": |
84 |
| - ... |
85 |
| - |
86 |
| - @overload |
87 |
| - def __call__( |
88 |
| - self, |
89 |
| - command: str, |
90 |
| - *, |
91 |
| - asynchronous: bool, |
92 |
| - **kwargs: Unpack[_BaseRunParams], |
93 |
| - ) -> Union["Promise", "Result"]: |
94 |
| - ... |
95 |
| - |
96 |
| - @overload |
97 |
| - def __call__( |
98 |
| - self, |
99 |
| - command: str, |
100 |
| - **kwargs: Unpack[_BaseRunParams], |
101 |
| - ) -> "Result": |
102 |
| - ... |
103 |
| - |
104 |
| - def __call__( |
105 |
| - self, |
106 |
| - command: str, |
107 |
| - **kwargs: Unpack[RunParams], |
108 |
| - ) -> Optional["Result"]: |
109 |
| - ... |
| 106 | + return cast("RunFunction", func) |
0 commit comments