Skip to content

Commit 01606f6

Browse files
Merge pull request #41 from ISISComputingGroup/ruff_and_pyright_ig
Ruff and pyright ig
2 parents 37207a0 + ce227c4 commit 01606f6

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,44 @@
11
"""
2-
Useful and slightly more explit exceptions that can be thrown. In general catch the super class of these.
2+
Useful and slightly more explicit exceptions that can be thrown.
3+
In general catch the super class of these.
34
"""
45

56

6-
class UnableToConnectToPVException(IOError):
7+
class UnableToConnectToPVException(IOError): # noqa N818 Historic name
78
"""
89
The system is unable to connect to a PV for some reason.
910
"""
1011

11-
def __init__(self, pv_name, err):
12+
def __init__(self, pv_name: str, err: str) -> None:
1213
super(UnableToConnectToPVException, self).__init__(
13-
"Unable to connect to PV {0}: {1}".format(pv_name, err)
14+
f"Unable to connect to PV {pv_name}: {err}"
1415
)
1516

1617

17-
class InvalidEnumStringException(KeyError):
18+
class InvalidEnumStringException(KeyError): # noqa N818 Historic name
1819
"""
1920
The enum string that is trying to be set is not listed in the pv.
2021
"""
2122

22-
def __init__(self, pv_name, valid_states):
23+
def __init__(self, pv_name: str, valid_states: str) -> None:
2324
super(InvalidEnumStringException, self).__init__(
24-
"Invalid string value entered for {}. Valid strings are {}".format(
25-
pv_name, valid_states
26-
)
25+
f"Invalid string value entered for {pv_name}. Valid strings are {valid_states}"
2726
)
2827

2928

30-
class ReadAccessException(IOError):
29+
class ReadAccessException(IOError): # noqa N818 Historic name
3130
"""
3231
PV exists but its value is unavailable to read.
3332
"""
3433

35-
def __init__(self, pv_name):
36-
super(ReadAccessException, self).__init__("Read access denied for PV {}".format(pv_name))
34+
def __init__(self, pv_name: str) -> None:
35+
super(ReadAccessException, self).__init__(f"Read access denied for PV {pv_name}")
3736

3837

39-
class WriteAccessException(IOError):
38+
class WriteAccessException(IOError): # noqa N818 Historic name
4039
"""
4140
PV was written to but does not allow writes.
4241
"""
4342

44-
def __init__(self, pv_name):
45-
super(WriteAccessException, self).__init__("Write access denied for PV {}".format(pv_name))
43+
def __init__(self, pv_name: str) -> None:
44+
super(WriteAccessException, self).__init__(f"Write access denied for PV {pv_name}")

src/genie_python/genie_alerts.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
This module is used for setting alerts on blocks.
55
"""
66

7-
from __future__ import absolute_import, print_function
8-
97
from genie_python.genie_api_setup import (
108
__api,
119
helparglist,
@@ -25,9 +23,16 @@
2523

2624

2725
@usercommand
28-
@helparglist("block, lowlimit, highlimit, [delay_in, delay_out]")
26+
@helparglist("block, lowlimit, highlimit, [set_enable, delay_in, delay_out]")
2927
@log_command_and_handle_exception
30-
def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_out=None):
28+
def set_range(
29+
block: str,
30+
lowlimit: float,
31+
highlimit: float,
32+
set_enable: bool = True,
33+
delay_in: float | None = None,
34+
delay_out: float | None = None,
35+
) -> None:
3136
"""
3237
Sets alert range on block.
3338
@@ -36,8 +41,10 @@ def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_
3641
lowlimit (float): low limit
3742
highlimit (float): high limit
3843
set_enable (bool): (optional setting True will enable alerts on the block. Defaults to True.
39-
delay_in (float): (optional) delay /s before triggering in range. If not specified the delay remains unchanged.
40-
delay_out (float): (optional) delay /s before triggering out of range. If not specified the delay remains unchanged.
44+
delay_in (float): (optional) delay /s before triggering in range. If not specified the delay
45+
remains unchanged.
46+
delay_out (float): (optional) delay /s before triggering out of range.
47+
If not specified the delay remains unchanged.
4148
4249
"""
4350
if not __api.block_exists(block):
@@ -56,7 +63,7 @@ def set_range(block, lowlimit, highlimit, set_enable=True, delay_in=None, delay_
5663
@usercommand
5764
@helparglist("block [, is_enabled]")
5865
@log_command_and_handle_exception
59-
def enable(block, set_enabled=True):
66+
def enable(block: str, set_enabled: bool = True) -> None:
6067
"""
6168
Enable alerts on a block.
6269
@@ -73,7 +80,7 @@ def enable(block, set_enabled=True):
7380
@usercommand
7481
@helparglist("message")
7582
@log_command_and_handle_exception
76-
def send(message):
83+
def send(message: str) -> None:
7784
"""
7885
Send a message to all alert recipients.
7986
@@ -87,7 +94,7 @@ def send(message):
8794
## no log decorator so mobile numbers not sent to log file
8895
@usercommand
8996
@helparglist("numbers")
90-
def set_sms(numbers):
97+
def set_sms(numbers: list[str] | str) -> None:
9198
"""
9299
Set SMS text numbers for alerts on blocks.
93100
@@ -107,7 +114,7 @@ def set_sms(numbers):
107114
## no log decorator so email addresses not sent to log file
108115
@usercommand
109116
@helparglist("emails")
110-
def set_email(emails):
117+
def set_email(emails: list[str] | str) -> None:
111118
"""
112119
Set email addresses for alerts on blocks.
113120
@@ -124,7 +131,7 @@ def set_email(emails):
124131
print("Unable to set alert email addresses: {}".format(e))
125132

126133

127-
def _print_block(block, only_if_enabled=False):
134+
def _print_block(block: str, only_if_enabled: bool = False) -> None:
128135
enabled = (
129136
__api.get_pv_value(_ALERT_ENABLE.format(block), to_string=True, is_local=True) == "YES"
130137
)
@@ -157,7 +164,7 @@ def _print_block(block, only_if_enabled=False):
157164
@usercommand
158165
@helparglist("[block, all]")
159166
@log_command_and_handle_exception
160-
def status(block=None, all=False):
167+
def status(block: str | None = None, all: bool = False) -> None:
161168
"""
162169
Prints the emails and mobiles used for alerts and the current status of specified block.
163170
Args:
@@ -177,12 +184,14 @@ def status(block=None, all=False):
177184

178185

179186
# used as part of tests, returns a dictionary of details
180-
def _dump(block):
187+
def _dump(block: str) -> dict[str, str]:
181188
if not __api.block_exists(block):
182189
raise Exception('No block with the name "{}" exists'.format(block))
183190
res = {}
184-
res["emails"] = __api.get_pv_value(_ALERT_EMAILS, to_string=True, is_local=True).split(";")
185-
res["mobiles"] = __api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True).split(";")
191+
res["emails"] = str(__api.get_pv_value(_ALERT_EMAILS, to_string=True, is_local=True)).split(";")
192+
res["mobiles"] = str(__api.get_pv_value(_ALERT_MOBILES, to_string=True, is_local=True)).split(
193+
";"
194+
)
186195
res["enabled"] = __api.get_pv_value(_ALERT_ENABLE.format(block), to_string=False, is_local=True)
187196
res["lowlimit"] = __api.get_pv_value(_ALERT_LOW.format(block), to_string=False, is_local=True)
188197
res["highlimit"] = __api.get_pv_value(_ALERT_HIGH.format(block), to_string=False, is_local=True)

0 commit comments

Comments
 (0)