Skip to content

Commit 8c7165c

Browse files
committed
fix both genie advanced and pre/post pyright and ruff
1 parent 398b712 commit 8c7165c

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/genie_python/genie_advanced.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import contextlib
88
from datetime import UTC, datetime, timedelta
99
from time import sleep
10-
from typing import Any, Callable, Iterator, TypedDict
10+
from typing import Any, Iterator, ParamSpec, Protocol, TypedDict
1111

1212
import numpy as np
1313
import numpy.typing as npt
@@ -21,6 +21,13 @@
2121
from genie_python.genie_waitfor import DELAY_IN_WAIT_FOR_SLEEP_LOOP
2222
from genie_python.utilities import check_break
2323

24+
P = ParamSpec("P")
25+
26+
27+
class PrePostCmd(Protocol):
28+
def __call__(self, **kwargs: Any) -> str | None:
29+
pass
30+
2431

2532
@usercommand
2633
@helparglist("")
@@ -174,7 +181,7 @@ def wait_for_pv(
174181

175182
@usercommand
176183
@helparglist("")
177-
def set_begin_precmd(begin_precmd: Callable[[Any], str | None]) -> None:
184+
def set_begin_precmd(begin_precmd: PrePostCmd) -> None:
178185
"""
179186
Set the function to call before the begin command.
180187
@@ -187,7 +194,7 @@ def set_begin_precmd(begin_precmd: Callable[[Any], str | None]) -> None:
187194

188195
@usercommand
189196
@helparglist("")
190-
def set_begin_postcmd(begin_postcmd: Callable[[Any], str | None]) -> None:
197+
def set_begin_postcmd(begin_postcmd: PrePostCmd) -> None:
191198
"""
192199
Set the function to call after the begin command.
193200
@@ -199,7 +206,7 @@ def set_begin_postcmd(begin_postcmd: Callable[[Any], str | None]) -> None:
199206

200207
@usercommand
201208
@helparglist("")
202-
def set_abort_precmd(abort_precmd: Callable[[Any], str | None]) -> None:
209+
def set_abort_precmd(abort_precmd: PrePostCmd) -> None:
203210
"""
204211
Set the function to call before the abort command.
205212
@@ -211,7 +218,7 @@ def set_abort_precmd(abort_precmd: Callable[[Any], str | None]) -> None:
211218

212219
@usercommand
213220
@helparglist("")
214-
def set_abort_postcmd(abort_postcmd: Callable[[Any], str | None]) -> None:
221+
def set_abort_postcmd(abort_postcmd: PrePostCmd) -> None:
215222
"""
216223
Set the function to call after the abort command.
217224
@@ -223,7 +230,7 @@ def set_abort_postcmd(abort_postcmd: Callable[[Any], str | None]) -> None:
223230

224231
@usercommand
225232
@helparglist("")
226-
def set_end_precmd(end_precmd: Callable[[Any], str | None]) -> None:
233+
def set_end_precmd(end_precmd: PrePostCmd) -> None:
227234
"""
228235
Set the function to call before the end command.
229236
@@ -235,7 +242,7 @@ def set_end_precmd(end_precmd: Callable[[Any], str | None]) -> None:
235242

236243
@usercommand
237244
@helparglist("")
238-
def set_end_postcmd(end_postcmd: Callable[[Any], str | None]) -> None:
245+
def set_end_postcmd(end_postcmd: PrePostCmd) -> None:
239246
"""
240247
Set the function to call after the end command.
241248
@@ -247,7 +254,7 @@ def set_end_postcmd(end_postcmd: Callable[[Any], str | None]) -> None:
247254

248255
@usercommand
249256
@helparglist("")
250-
def set_pause_precmd(pause_precmd: Callable[[Any], str | None]) -> None:
257+
def set_pause_precmd(pause_precmd: PrePostCmd) -> None:
251258
"""
252259
Set the function to call before the pause command.
253260
@@ -259,7 +266,7 @@ def set_pause_precmd(pause_precmd: Callable[[Any], str | None]) -> None:
259266

260267
@usercommand
261268
@helparglist("")
262-
def set_pause_postcmd(pause_postcmd: Callable[[Any], str | None]) -> None:
269+
def set_pause_postcmd(pause_postcmd: PrePostCmd) -> None:
263270
"""
264271
Set the function to call after the pause command.
265272
@@ -271,7 +278,7 @@ def set_pause_postcmd(pause_postcmd: Callable[[Any], str | None]) -> None:
271278

272279
@usercommand
273280
@helparglist("")
274-
def set_resume_precmd(resume_precmd: Callable[[Any], str | None]) -> None:
281+
def set_resume_precmd(resume_precmd: PrePostCmd) -> None:
275282
"""
276283
Set the function to call before the resume command.
277284
@@ -283,7 +290,7 @@ def set_resume_precmd(resume_precmd: Callable[[Any], str | None]) -> None:
283290

284291
@usercommand
285292
@helparglist("")
286-
def set_resume_postcmd(resume_postcmd: Callable[[Any], str | None]) -> None:
293+
def set_resume_postcmd(resume_postcmd: PrePostCmd) -> None:
287294
"""
288295
Set the function to call after the resume command.
289296

src/genie_python/genie_pre_post_cmd_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from builtins import object
2-
from typing import Any, Callable
2+
from typing import Any
33

44

55
class PrePostCmdManager(object):
66
"""
77
A class to manager the precmd and postcmd commands such as used in begin, end, abort, resume,
88
pause.
99
"""
10+
1011
def begin_precmd(self, **kwargs: Any) -> str | None:
1112
return
1213

0 commit comments

Comments
 (0)