Skip to content

Commit 9476c62

Browse files
author
Kristoffel Pirard
committed
prior: fix AttributeError for bad connections
When constructing a ProScanIII object on a port that does not contain a prior controller, the _devices member is not defined. This causes the __del__ operation of the object to fail, because it will end up in the base class' __del__, which requires the `devices` property, which requires the `_devices` member to be present. Conceptually, the `abc.Controller` class requires the implementation to be a valid object. the `super().__init__` method may call any of the public base members, so we have to make sure they are valid before calling it. One may also argue that the object is not allowed to be constructed at all if not connected to a proper device; that would be an alternative fix.
1 parent 2c282da commit 9476c62

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

microscope/controllers/prior.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,18 @@ class ProScanIII(microscope.abc.Controller):
211211
def __init__(
212212
self, port: str, baudrate: int = 9600, timeout: float = 0.5, **kwargs
213213
) -> None:
214-
super().__init__(**kwargs)
215-
self._conn = _ProScanIIIConnection(port, baudrate, timeout)
216214
self._devices: Mapping[str, microscope.abc.Device] = {}
217215

216+
self._conn = _ProScanIIIConnection(port, baudrate, timeout)
217+
218218
# Can have up to three filter wheels, numbered 1 to 3.
219219
for number in range(1, 4):
220220
if self._conn.has_filterwheel(number):
221221
key = "filter %d" % number
222222
self._devices[key] = _ProScanIIIFilterWheel(self._conn, number)
223223

224+
super().__init__(**kwargs)
225+
224226
@property
225227
def devices(self) -> Mapping[str, microscope.abc.Device]:
226228
return self._devices

0 commit comments

Comments
 (0)