Skip to content

Commit 07ad083

Browse files
Merge pull request #43 from ISISComputingGroup/Ticket8553_pyright_day_genie_blockserver
Ruff and pyright fixes
2 parents 01606f6 + a39f1bc commit 07ad083

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

src/genie_python/genie_blockserver.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
import time
44
from builtins import object
5+
from typing import TYPE_CHECKING, Any, Callable, ParamSpec, TypeVar
56

67
from genie_python.utilities import compress_and_hex, dehex_decompress_and_dejson
78

9+
if TYPE_CHECKING:
10+
from genie_python.genie import PVValue
11+
from genie_python.genie_epics_api import API
12+
13+
Param = ParamSpec("Param")
14+
RetType = TypeVar("RetType")
15+
816
# Prefix for block server pvs
917
PV_BLOCK_NAMES = "BLOCKNAMES"
1018
BLOCK_SERVER_PREFIX = "CS:BLOCKSERVER:"
1119

1220

13-
def _blockserver_retry(func):
14-
def wrapper(*args, **kwargs):
21+
def _blockserver_retry(func: Callable[Param, RetType]) -> Callable[Param, RetType]:
22+
def wrapper(*args: Param.args, **kwargs: Param.kwargs) -> RetType:
1523
while True:
1624
try:
1725
return func(*args, **kwargs)
@@ -27,38 +35,38 @@ def wrapper(*args, **kwargs):
2735

2836

2937
class BlockServer(object):
30-
def __init__(self, api):
31-
self.api = api
38+
def __init__(self, api: "API") -> None:
39+
self.api: "API" = api
3240

33-
def _get_pv_value(self, pv, as_string=False):
41+
def _get_pv_value(self, pv: str, as_string: bool = False) -> "PVValue":
3442
"""Just a convenient wrapper for calling the api's get_pv_value method"""
3543
return self.api.get_pv_value(self.api.prefix_pv_name(pv), as_string)
3644

37-
def _set_pv_value(self, pv, value, wait=False):
45+
def _set_pv_value(self, pv: str, value: "PVValue | bytes", wait: bool = False) -> None:
3846
"""Just a convenient wrapper for calling the api's set_pv_value method"""
3947
return self.api.set_pv_value(self.api.prefix_pv_name(pv), value, wait)
4048

4149
@_blockserver_retry
42-
def get_sample_par_names(self):
50+
def get_sample_par_names(self) -> Any: # noqa: ANN401
4351
"""Get the current sample parameter names as a list."""
4452
# Get the names from the blockserver
4553
raw = self._get_pv_value(BLOCK_SERVER_PREFIX + "SAMPLE_PARS", True)
4654
return dehex_decompress_and_dejson(raw)
4755

4856
@_blockserver_retry
49-
def get_beamline_par_names(self):
57+
def get_beamline_par_names(self) -> Any: # noqa: ANN401
5058
"""Get the current beamline parameter names as a list."""
5159
# Get the names from the blockserver
5260
raw = self._get_pv_value(BLOCK_SERVER_PREFIX + "BEAMLINE_PARS", True)
5361
return dehex_decompress_and_dejson(raw)
5462

5563
@_blockserver_retry
56-
def get_runcontrol_settings(self):
64+
def get_runcontrol_settings(self) -> Any: # noqa: ANN401
5765
"""Get the current run-control settings."""
5866
raw = self._get_pv_value(BLOCK_SERVER_PREFIX + "GET_RC_PARS", True)
5967
return dehex_decompress_and_dejson(raw)
6068

61-
def reload_current_config(self):
69+
def reload_current_config(self) -> None:
6270
"""Reload the current configuration."""
6371
raw = compress_and_hex("1")
6472
self._set_pv_value(BLOCK_SERVER_PREFIX + "RELOAD_CURRENT_CONFIG", raw, True)

src/genie_python/genie_cachannel_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def putCB(epics_args: Tuple[str, int, int, int], user_args: Tuple[Event, ...]) -
157157
@staticmethod
158158
def set_pv_value(
159159
name: str,
160-
value: "PVValue",
160+
value: "PVValue|bytes",
161161
wait: bool = False,
162162
timeout: float = TIMEOUT,
163163
safe_not_quick: bool = True,
@@ -403,7 +403,7 @@ def connect_to_pv(ca_channel: CaChannel) -> None:
403403
raise UnableToConnectToPVException(ca_channel.name(), "Connection timeout (state)")
404404

405405
@staticmethod
406-
def check_for_enum_value(value: "PVValue", chan: CaChannel, name: str) -> "PVValue":
406+
def check_for_enum_value(value: "PVValue|bytes", chan: CaChannel, name: str) -> "PVValue|bytes":
407407
"""
408408
Check for string input for MBBI/BI records and replace with the equivalent index value.
409409

src/genie_python/genie_epics_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def init_instrument(
312312
def set_pv_value(
313313
self,
314314
name: str,
315-
value: "PVValue",
315+
value: "PVValue|bytes",
316316
wait: bool = False,
317317
attempts: int = 3,
318318
is_local: bool = False,

src/genie_python/genie_p4p_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _log_error(message: str) -> None:
4747
@staticmethod
4848
def set_pv_value(
4949
name: str,
50-
value: "PVValue",
50+
value: "PVValue|bytes",
5151
wait: bool = False,
5252
timeout: float = TIMEOUT,
5353
safe_not_quick: bool = True,

src/genie_python/genie_pv_connection_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class GeniePvConnectionProtocol(Protocol):
1010
@staticmethod
1111
def set_pv_value(
12-
name: str, value: "PVValue", wait: bool, timeout: float, safe_not_quick: bool
12+
name: str, value: "PVValue|bytes", wait: bool, timeout: float, safe_not_quick: bool
1313
) -> None: ...
1414

1515
@staticmethod

0 commit comments

Comments
 (0)