Skip to content

Commit

Permalink
Ruff/pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Willemsen committed Oct 17, 2024
1 parent 2fca2e9 commit 88dfaeb
Show file tree
Hide file tree
Showing 10 changed files with 574 additions and 311 deletions.
2 changes: 1 addition & 1 deletion utils/build_architectures.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BuildArchitectures(Enum):
_32BIT = 2

@staticmethod
def archname(arch):
def archname(arch: str) -> str:
"""
Returns: nice name of architecture
"""
Expand Down
14 changes: 11 additions & 3 deletions utils/calibration_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import time
import typing
from contextlib import contextmanager

CAL_SEL_PV = "CAL:SEL"

if typing.TYPE_CHECKING:
from utils.channel_access import ChannelAccess

def set_calibration_file(channel_access, filename, prefix=""):

def set_calibration_file(channel_access: "ChannelAccess", filename: str, prefix: str = "") -> None:
"""
Sets a calibration file. Retries if it didn't set properly first time.
Args:
Expand All @@ -29,12 +33,16 @@ def set_calibration_file(channel_access, filename, prefix=""):
)


def reset_calibration_file(channel_access, default_file="None.txt", prefix=""):
def reset_calibration_file(
channel_access: "ChannelAccess", default_file: str = "None.txt", prefix: str = ""
) -> None:
set_calibration_file(channel_access, default_file, prefix)


@contextmanager
def use_calibration_file(channel_access, filename, default_file="None.txt", prefix=""):
def use_calibration_file(
channel_access: "ChannelAccess", filename: str, default_file: str = "None.txt", prefix: str = ""
) -> typing.Generator[None, None, None]:
set_calibration_file(channel_access, filename, prefix)
try:
yield
Expand Down
15 changes: 6 additions & 9 deletions utils/device_launcher.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from contextlib import contextmanager

try:
from contextlib import ExitStack # PY3
except ImportError:
from contextlib2 import ExitStack # PY2
from contextlib import ExitStack, contextmanager
from typing import ContextManager, Generator


@contextmanager
def device_launcher(ioc, lewis):
def device_launcher(ioc: ContextManager, lewis: ContextManager) -> Generator[None, None, None]:
"""
Context manager that launches an ioc and emulator pair
:param ioc: the ioc launcher
Expand All @@ -22,10 +18,11 @@ def device_launcher(ioc, lewis):


@contextmanager
def device_collection_launcher(devices):
def device_collection_launcher(devices: list[ContextManager]) -> Generator[None, None, None]:
"""
Context manager that launches a list of devices
:param devices: list of context managers representing the devices to launch (see device_launcher above)
:param devices: list of context managers representing the devices to launch
(see device_launcher above)
"""
with ExitStack() as stack:
for device in devices:
Expand Down
4 changes: 2 additions & 2 deletions utils/emulator_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class UnableToConnectToEmulatorException(IOError):
class UnableToConnectToEmulatorException(IOError): # noqa: N818 (historic name)
"""
The system is unable to connect to the emulator for some reason.
"""

def __init__(self, emulator_name, err):
def __init__(self, emulator_name: str, err: str | BaseException) -> None:
super(UnableToConnectToEmulatorException, self).__init__(
"Unable to connect to Emnulator {0}: {1}".format(emulator_name, err)
)
Loading

0 comments on commit 88dfaeb

Please sign in to comment.