Skip to content

Commit 27c651f

Browse files
committed
thought I'd need to change stuff in here, but turns out I didn't. Fixed the pyright here anyway
1 parent 9ed3bb0 commit 27c651f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/genie_python/genie_cachannel_wrapper.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from builtins import object
1010
from collections.abc import Callable
1111
from threading import Event
12-
from typing import TYPE_CHECKING, Optional, Tuple, TypeVar
12+
from typing import TYPE_CHECKING, Optional, Tuple, TypeVar, TypeGuard, overload, Literal
1313

1414
from CaChannel import CaChannel, CaChannelException, ca
1515

@@ -32,7 +32,10 @@
3232
)
3333

3434
if TYPE_CHECKING:
35-
from genie_python.genie import PVValue
35+
from genie_python.genie import PVValue, PVBaseValue
36+
37+
def is_int_or_str_list(val: list[PVBaseValue]) -> TypeGuard[list[int | str]]:
38+
return all(isinstance(x, int) or isinstance(x, str) for x in val)
3639

3740
from .channel_access_exceptions import (
3841
InvalidEnumStringException,
@@ -306,6 +309,8 @@ def get_pv_value(
306309
value = chan.getw(ca.DBR_CHAR)
307310
# Could see if the element count is > 1 instead
308311
if isinstance(value, list):
312+
if TYPE_CHECKING:
313+
assert is_int_or_str_list(value)
309314
return waveform_to_string(value)
310315
else:
311316
return str(value)
@@ -384,7 +389,7 @@ def connect_to_pv(ca_channel: CaChannel) -> None:
384389
try:
385390
ca_channel.search_and_connect(None, CaChannelWrapper.putCB, event)
386391
except CaChannelException as e:
387-
raise UnableToConnectToPVException(ca_channel.name(), e)
392+
raise UnableToConnectToPVException(ca_channel.name(), str(e))
388393

389394
ca_channel.flush_io()
390395

@@ -451,6 +456,8 @@ def add_monitor(
451456
when the pv disconnects
452457
use_numpy (bool, optional): True use numpy to return arrays,
453458
False return a list; None for use the default
459+
to_string: if set to true, will ensure anything passed to call_back_function's value
460+
is a string
454461
Returns:
455462
unsubscribe event function
456463
"""

0 commit comments

Comments
 (0)