Skip to content

Commit 5090e6e

Browse files
authored
fix: change action type hint on MDAEvent (#108)
* fix: change action type * test: add test
1 parent e50aa35 commit 5090e6e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/useq/_actions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Union
2+
13
from typing_extensions import Literal
24

35
from useq._base_model import FrozenModel
@@ -54,3 +56,6 @@ class HardwareAutofocus(Action):
5456
autofocus_device_name: str
5557
autofocus_motor_offset: float
5658
max_retries: int = 3
59+
60+
61+
AnyAction = Union[HardwareAutofocus, AcquireImage]

src/useq/_mda_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from pydantic import Field, validator
1717

18-
from useq._actions import AcquireImage, Action
18+
from useq._actions import AcquireImage, AnyAction
1919
from useq._base_model import UseqModel
2020
from useq._utils import ReadOnlyDict
2121

@@ -138,7 +138,7 @@ class MDAEvent(UseqModel):
138138
sequence: Optional[MDASequence] = Field(default=None, repr=False)
139139
properties: Optional[List[PropertyTuple]] = None
140140
metadata: Dict[str, Any] = Field(default_factory=dict)
141-
action: Action = Field(default_factory=AcquireImage)
141+
action: AnyAction = Field(default_factory=AcquireImage)
142142
keep_shutter_open: bool = False
143143

144144
# action

tests/test_sequence.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,8 @@ def test_mda_warns_extra() -> None:
321321
def test_skip_channel_do_stack_no_zplan():
322322
mda = MDASequence(channels=[{"config": "DAPI", "do_stack": False}])
323323
assert len(list(mda)) == 1
324+
325+
326+
def test_event_action_union() -> None:
327+
# test that action unions work
328+
MDAEvent(action={"autofocus_device_name": "Z", "autofocus_motor_offset": 25})

0 commit comments

Comments
 (0)