Skip to content

Commit

Permalink
Fix various type linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuck99 committed Oct 22, 2024
1 parent 5736ad7 commit 431b950
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
16 changes: 7 additions & 9 deletions src/dodal/common/signal_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from collections.abc import Callable, Coroutine
from typing import Any, TypeVar
from typing import Any

from bluesky.protocols import Reading
from ophyd_async.core import SignalR, SoftSignalBackend
from ophyd_async.core import SignalDatatypeT, SignalR, SoftSignalBackend

T = TypeVar("T")


class HardwareBackedSoftSignalBackend(SoftSignalBackend[T]):
class HardwareBackedSoftSignalBackend(SoftSignalBackend[SignalDatatypeT]):
def __init__(
self,
get_from_hardware_func: Callable[[], Coroutine[Any, Any, T]],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
*args,
**kwargs,
) -> None:
Expand All @@ -25,14 +23,14 @@ async def get_reading(self) -> Reading:
await self._update_value()
return await super().get_reading()

async def get_value(self) -> T:
async def get_value(self) -> SignalDatatypeT:
await self._update_value()
return await super().get_value()


def create_hardware_backed_soft_signal(
datatype: type[T],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, T]],
datatype: type[SignalDatatypeT],
get_from_hardware_func: Callable[[], Coroutine[Any, Any, SignalDatatypeT]],
units: str | None = None,
precision: int | None = None,
):
Expand Down
8 changes: 4 additions & 4 deletions src/dodal/devices/aperturescatterguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AperturePosition(BaseModel):
aperture_z: float
scatterguard_x: float
scatterguard_y: float
radius: float | None = Field(json_schema_extra={"units": "µm"}, default=None)
radius: float = Field(json_schema_extra={"units": "µm"}, default=0.0)

@property
def values(self) -> tuple[float, float, float, float, float]:
Expand All @@ -54,7 +54,7 @@ def tolerances_from_gda_params(
@staticmethod
def from_gda_params(
name: ApertureValue,
radius: float | None,
radius: float,
params: GDABeamlineParameters,
) -> AperturePosition:
return AperturePosition(
Expand All @@ -81,7 +81,7 @@ def load_positions_from_beamline_parameters(
) -> dict[ApertureValue, AperturePosition]:
return {
ApertureValue.ROBOT_LOAD: AperturePosition.from_gda_params(
ApertureValue.ROBOT_LOAD, None, params
ApertureValue.ROBOT_LOAD, 0, params
),
ApertureValue.SMALL: AperturePosition.from_gda_params(
ApertureValue.SMALL, 20, params
Expand Down Expand Up @@ -172,7 +172,7 @@ async def _get_current_aperture_position(self) -> ApertureValue:

raise InvalidApertureMove("Current aperture/scatterguard state unrecognised")

async def _get_current_radius(self) -> float | None:
async def _get_current_radius(self) -> float:
current_value = await self._get_current_aperture_position()
return self._loaded_positions[current_value].radius

Expand Down
2 changes: 1 addition & 1 deletion src/dodal/devices/oav/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ def wait_for_tip_to_be_found(
timeout = yield from bps.rd(ophyd_pin_tip_detection.validity_timeout)
raise PinNotFoundException(f"No pin found after {timeout} seconds")

return found_tip # type: ignore
return Pixel((int(found_tip[0]), int(found_tip[1]))) # type: ignore
2 changes: 1 addition & 1 deletion tests/devices/unit_tests/test_aperture_scatterguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def test_aperture_unsafe_move(
aperture_z=5.6,
scatterguard_x=7.8,
scatterguard_y=9.0,
radius=None,
radius=0,
)
ap_sg = aperture_in_medium_pos
await ap_sg._set_raw_unsafe(pos)
Expand Down
7 changes: 5 additions & 2 deletions tests/devices/unit_tests/test_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async def test_given_tip_found_when_wait_for_tip_to_be_found_called_then_tip_imm
)
RE = RunEngine(call_returns_result=True)
result = RE(wait_for_tip_to_be_found(mock_pin_tip_detect))
assert all(result.plan_result == (100, 100))
assert result.plan_result == (100, 100) # type: ignore
mock_pin_tip_detect._get_tip_and_edge_data.assert_called_once()


Expand All @@ -254,7 +254,10 @@ async def test_given_no_tip_when_wait_for_tip_to_be_found_called_then_exception_
await mock_pin_tip_detect.validity_timeout.set(0.2)
mock_pin_tip_detect._get_tip_and_edge_data = AsyncMock(
return_value=SampleLocation(
*PinTipDetection.INVALID_POSITION, np.array([]), np.array([])
int(PinTipDetection.INVALID_POSITION[0]),
int(PinTipDetection.INVALID_POSITION[1]),
np.array([]),
np.array([]),
)
)
RE = RunEngine(call_returns_result=True)
Expand Down

0 comments on commit 431b950

Please sign in to comment.