From d2aebf8b10cadfbc6f129687ff443c86b3fd5867 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 28 Apr 2026 14:50:04 +0100 Subject: [PATCH] Make properties of JPEGSharpnessMonitor read-only For thread-safety reasons we should not modify the lists used by `JPEGSharpnessMonitor`. This commit marks them as read-only properties and types them as `Sequence` so `mypy` should flag if they get modified. --- .../things/autofocus.py | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/openflexure_microscope_server/things/autofocus.py b/src/openflexure_microscope_server/things/autofocus.py index 61d1ff0a..5e8c9c85 100644 --- a/src/openflexure_microscope_server/things/autofocus.py +++ b/src/openflexure_microscope_server/things/autofocus.py @@ -263,10 +263,30 @@ class JPEGSharpnessMonitor: self.camera = camera self.stage = stage LOGGER.debug(f"Created sharpness monitor with {stage}, {camera}") - self.stage_positions: list[Mapping[str, int]] = [] - self.stage_times: list[float] = [] - self.jpeg_times: list[float] = [] - self.jpeg_sizes: list[int] = [] + self._stage_positions: list[Mapping[str, int]] = [] + self._stage_times: list[float] = [] + self._jpeg_times: list[float] = [] + self._jpeg_sizes: list[int] = [] + + @property + def stage_positions(self) -> Sequence[Mapping[str, int]]: + """The positions recorded for the stage.""" + return self._stage_positions + + @property + def stage_times(self) -> Sequence[float]: + """The timestamps recorded for stage position updates.""" + return self._stage_times + + @property + def jpeg_times(self) -> Sequence[float]: + """The timestamps recorded for captured JPEG frames.""" + return self._jpeg_times + + @property + def jpeg_sizes(self) -> Sequence[int]: + """The recorded JPEG frame sizes used as a sharpness metric.""" + return self._jpeg_sizes running = False