From cb9270c9e8e19805acab0fa4dbf42e208a656766 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Mon, 30 Mar 2026 17:05:14 +0100 Subject: [PATCH] Use a default_factory for dict default values `backlash_steps` and `axis_inverted` were `lt.setting`s with default values that were dictionaries. This means they had mutable default values, which caused crosstalk in the test suite. This commit swaps them to default factory functions. This should isolate instances from each other and stop the offending behaviour. --- src/openflexure_microscope_server/things/stage/__init__.py | 4 ++-- src/openflexure_microscope_server/things/stage/dummy.py | 2 +- src/openflexure_microscope_server/things/stage/sangaboard.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openflexure_microscope_server/things/stage/__init__.py b/src/openflexure_microscope_server/things/stage/__init__.py index 3298e2ac..d0bdeab6 100644 --- a/src/openflexure_microscope_server/things/stage/__init__.py +++ b/src/openflexure_microscope_server/things/stage/__init__.py @@ -147,7 +147,7 @@ class BaseStage(lt.Thing): return self._apply_axis_direction(self._hardware_position) backlash_steps: dict[str, int] = lt.setting( - default={"x": 200, "y": 200, "z": 200}, readonly=True + default_factory=lambda: {"x": 200, "y": 200, "z": 200}, readonly=True ) """The number of steps to elimate backlash. The sign sets the direction. @@ -161,7 +161,7 @@ class BaseStage(lt.Thing): """Whether the stage is in motion.""" axis_inverted: dict[str, bool] = lt.setting( - default={"x": False, "y": False, "z": False}, readonly=True + default_factory=lambda: {"x": False, "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/dummy.py b/src/openflexure_microscope_server/things/stage/dummy.py index 4948d266..c1b0e5c5 100644 --- a/src/openflexure_microscope_server/things/stage/dummy.py +++ b/src/openflexure_microscope_server/things/stage/dummy.py @@ -77,7 +77,7 @@ class DummyStage(BaseStage): self._move_thread.join() axis_inverted: dict[str, bool] = lt.setting( - default={"x": True, "y": False, "z": False}, readonly=True + default_factory=lambda: {"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 a6c99eb9..b8ad994c 100644 --- a/src/openflexure_microscope_server/things/stage/sangaboard.py +++ b/src/openflexure_microscope_server/things/stage/sangaboard.py @@ -76,7 +76,7 @@ class SangaboardThing(BaseStage): self._sangaboard.close() axis_inverted: dict[str, bool] = lt.setting( - default={"x": True, "y": False, "z": True}, readonly=True + default_factory=lambda: {"x": True, "y": False, "z": True}, readonly=True ) """Used to convert coordinates between the program frame and the hardware frame."""