7
7
import contextlib
8
8
from datetime import UTC , datetime , timedelta
9
9
from time import sleep
10
- from typing import Any , Callable , Iterator , TypedDict
10
+ from typing import Any , Iterator , ParamSpec , Protocol , TypedDict
11
11
12
12
import numpy as np
13
13
import numpy .typing as npt
21
21
from genie_python .genie_waitfor import DELAY_IN_WAIT_FOR_SLEEP_LOOP
22
22
from genie_python .utilities import check_break
23
23
24
+ P = ParamSpec ("P" )
25
+
26
+
27
+ class PrePostCmd (Protocol ):
28
+ def __call__ (self , ** kwargs : Any ) -> str | None :
29
+ pass
30
+
24
31
25
32
@usercommand
26
33
@helparglist ("" )
@@ -174,7 +181,7 @@ def wait_for_pv(
174
181
175
182
@usercommand
176
183
@helparglist ("" )
177
- def set_begin_precmd (begin_precmd : Callable [[ Any ], str | None ] ) -> None :
184
+ def set_begin_precmd (begin_precmd : PrePostCmd ) -> None :
178
185
"""
179
186
Set the function to call before the begin command.
180
187
@@ -187,7 +194,7 @@ def set_begin_precmd(begin_precmd: Callable[[Any], str | None]) -> None:
187
194
188
195
@usercommand
189
196
@helparglist ("" )
190
- def set_begin_postcmd (begin_postcmd : Callable [[ Any ], str | None ] ) -> None :
197
+ def set_begin_postcmd (begin_postcmd : PrePostCmd ) -> None :
191
198
"""
192
199
Set the function to call after the begin command.
193
200
@@ -199,7 +206,7 @@ def set_begin_postcmd(begin_postcmd: Callable[[Any], str | None]) -> None:
199
206
200
207
@usercommand
201
208
@helparglist ("" )
202
- def set_abort_precmd (abort_precmd : Callable [[ Any ], str | None ] ) -> None :
209
+ def set_abort_precmd (abort_precmd : PrePostCmd ) -> None :
203
210
"""
204
211
Set the function to call before the abort command.
205
212
@@ -211,7 +218,7 @@ def set_abort_precmd(abort_precmd: Callable[[Any], str | None]) -> None:
211
218
212
219
@usercommand
213
220
@helparglist ("" )
214
- def set_abort_postcmd (abort_postcmd : Callable [[ Any ], str | None ] ) -> None :
221
+ def set_abort_postcmd (abort_postcmd : PrePostCmd ) -> None :
215
222
"""
216
223
Set the function to call after the abort command.
217
224
@@ -223,7 +230,7 @@ def set_abort_postcmd(abort_postcmd: Callable[[Any], str | None]) -> None:
223
230
224
231
@usercommand
225
232
@helparglist ("" )
226
- def set_end_precmd (end_precmd : Callable [[ Any ], str | None ] ) -> None :
233
+ def set_end_precmd (end_precmd : PrePostCmd ) -> None :
227
234
"""
228
235
Set the function to call before the end command.
229
236
@@ -235,7 +242,7 @@ def set_end_precmd(end_precmd: Callable[[Any], str | None]) -> None:
235
242
236
243
@usercommand
237
244
@helparglist ("" )
238
- def set_end_postcmd (end_postcmd : Callable [[ Any ], str | None ] ) -> None :
245
+ def set_end_postcmd (end_postcmd : PrePostCmd ) -> None :
239
246
"""
240
247
Set the function to call after the end command.
241
248
@@ -247,7 +254,7 @@ def set_end_postcmd(end_postcmd: Callable[[Any], str | None]) -> None:
247
254
248
255
@usercommand
249
256
@helparglist ("" )
250
- def set_pause_precmd (pause_precmd : Callable [[ Any ], str | None ] ) -> None :
257
+ def set_pause_precmd (pause_precmd : PrePostCmd ) -> None :
251
258
"""
252
259
Set the function to call before the pause command.
253
260
@@ -259,7 +266,7 @@ def set_pause_precmd(pause_precmd: Callable[[Any], str | None]) -> None:
259
266
260
267
@usercommand
261
268
@helparglist ("" )
262
- def set_pause_postcmd (pause_postcmd : Callable [[ Any ], str | None ] ) -> None :
269
+ def set_pause_postcmd (pause_postcmd : PrePostCmd ) -> None :
263
270
"""
264
271
Set the function to call after the pause command.
265
272
@@ -271,7 +278,7 @@ def set_pause_postcmd(pause_postcmd: Callable[[Any], str | None]) -> None:
271
278
272
279
@usercommand
273
280
@helparglist ("" )
274
- def set_resume_precmd (resume_precmd : Callable [[ Any ], str | None ] ) -> None :
281
+ def set_resume_precmd (resume_precmd : PrePostCmd ) -> None :
275
282
"""
276
283
Set the function to call before the resume command.
277
284
@@ -283,7 +290,7 @@ def set_resume_precmd(resume_precmd: Callable[[Any], str | None]) -> None:
283
290
284
291
@usercommand
285
292
@helparglist ("" )
286
- def set_resume_postcmd (resume_postcmd : Callable [[ Any ], str | None ] ) -> None :
293
+ def set_resume_postcmd (resume_postcmd : PrePostCmd ) -> None :
287
294
"""
288
295
Set the function to call after the resume command.
289
296
0 commit comments