From 9976c5cb849e68c79f2f7b42ee043d96b2c128c2 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Fri, 19 Dec 2025 10:27:55 +0000 Subject: [PATCH] Fix stage typehints --- .../things/stage/__init__.py | 16 ++++++++++++---- .../things/stage/dummy.py | 3 +-- .../things/stage/sangaboard.py | 3 +-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/openflexure_microscope_server/things/stage/__init__.py b/src/openflexure_microscope_server/things/stage/__init__.py index b8de8e19..fd495186 100644 --- a/src/openflexure_microscope_server/things/stage/__init__.py +++ b/src/openflexure_microscope_server/things/stage/__init__.py @@ -12,7 +12,7 @@ As the object will be used as a context manager create the hardware connection i from __future__ import annotations from collections.abc import Mapping, Sequence -from typing import Any, Literal, Never +from typing import Any, Literal, overload import labthings_fastapi as lt @@ -82,11 +82,19 @@ class BaseStage(lt.Thing): moving: bool = lt.property(default=False, readonly=True) """Whether the stage is in motion.""" - axis_inverted: Mapping[str, bool] = lt.setting( + axis_inverted: dict[str, bool] = lt.setting( default={"x": False, "y": False, "z": False}, readonly=True ) """Used to convert coordinates between the program frame and the hardware frame.""" + @overload + def _apply_axis_direction(self, position: list[int] | tuple[int]) -> list[int]: ... + + @overload + def _apply_axis_direction( + self, position: Mapping[str, int] + ) -> Mapping[str, int]: ... + def _apply_axis_direction( self, position: list[int] | tuple[int] | Mapping[str, int] ) -> list[int] | Mapping[str, int]: @@ -142,7 +150,7 @@ class BaseStage(lt.Thing): def _hardware_move_relative( self, block_cancellation: bool = False, **kwargs: int - ) -> Never: + ) -> None: """Make a relative move in the coordinate system used by the physical hardware. Make sure to use and update ``self._hardware_position`` not ``self.position``. @@ -163,7 +171,7 @@ class BaseStage(lt.Thing): self, block_cancellation: bool = False, **kwargs: int, - ) -> Never: + ) -> None: """Make a absolute move in the coordinate system used by the physical hardware. Make sure to use and update ``self._hardware_position`` not ``self.position``. diff --git a/src/openflexure_microscope_server/things/stage/dummy.py b/src/openflexure_microscope_server/things/stage/dummy.py index a535fb3c..7130fcb7 100644 --- a/src/openflexure_microscope_server/things/stage/dummy.py +++ b/src/openflexure_microscope_server/things/stage/dummy.py @@ -3,7 +3,6 @@ from __future__ import annotations import time -from collections.abc import Mapping from types import TracebackType from typing import Any, Optional, Self @@ -49,7 +48,7 @@ class DummyStage(BaseStage): ) -> None: """Nothing to do when the Thing context manager is closed.""" - axis_inverted: Mapping[str, bool] = lt.setting( + axis_inverted: dict[str, bool] = lt.setting( default={"x": True, "y": False, "z": False}, readonly=True ) """Used to convert coordinates between the program frame and the hardware frame.""" diff --git a/src/openflexure_microscope_server/things/stage/sangaboard.py b/src/openflexure_microscope_server/things/stage/sangaboard.py index d50ad539..db64ccc3 100644 --- a/src/openflexure_microscope_server/things/stage/sangaboard.py +++ b/src/openflexure_microscope_server/things/stage/sangaboard.py @@ -4,7 +4,6 @@ from __future__ import annotations import threading import time -from collections.abc import Mapping from contextlib import contextmanager from copy import copy from types import TracebackType @@ -81,7 +80,7 @@ class SangaboardThing(BaseStage): with self._sangaboard_lock: yield self._sangaboard - axis_inverted: Mapping[str, bool] = lt.setting( + axis_inverted: dict[str, bool] = lt.setting( default={"x": True, "y": False, "z": True}, readonly=True ) """Used to convert coordinates between the program frame and the hardware frame."""