Skip to content

Commit 4ac0ccf

Browse files
committed
Remove *args from all devices __init__ (issue #84)
Take only **kwargs when constructing a device instance. This makes it clear which of the classes will process a given argument. Should enable us to make better use of multiple hierarchy. All cameras and the ThorlabsFilterWheel already discarded `*args` and the deviceserver already only works with `**kwargs` anyway.
1 parent a4e3a08 commit 4ac0ccf

File tree

13 files changed

+43
-43
lines changed

13 files changed

+43
-43
lines changed

microscope/cameras/andorsdk3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def wrapper(self, *args, **kwargs):
101101
class AndorSDK3(devices.FloatingDeviceMixin,
102102
devices.CameraDevice):
103103
SDK_INITIALIZED = False
104-
def __init__(self, index=0, *args, **kwargs):
104+
def __init__(self, index=0, **kwargs):
105105
super(AndorSDK3, self).__init__(index=index, **kwargs)
106106
if not AndorSDK3.SDK_INITIALIZED:
107107
SDK3.InitialiseLibrary()

microscope/cameras/atmcd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ def __str__(self):
11391139
class AndorAtmcd(devices.FloatingDeviceMixin,
11401140
devices.CameraDevice):
11411141
""" Implements CameraDevice interface for Andor ATMCD library."""
1142-
def __init__(self, index=0, *args, **kwargs):
1142+
def __init__(self, index=0, **kwargs):
11431143
super().__init__(index=index, **kwargs)
11441144
# Recursion depth for context manager behaviour.
11451145
self._rdepth = 0

microscope/cameras/pvcam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ class PVCamera(devices.FloatingDeviceMixin, devices.CameraDevice):
11851185
open_cameras = []
11861186

11871187

1188-
def __init__(self, index=0, *args, **kwargs):
1188+
def __init__(self, index=0, **kwargs):
11891189
super(PVCamera, self).__init__(index=index, **kwargs)
11901190
# Camera name in DLL.
11911191
self._pv_name = None

microscope/devices.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class CameraDevice(DataDevice):
641641
"""
642642
ALLOWED_TRANSFORMS = [p for p in itertools.product(*3 * [[False, True]])]
643643

644-
def __init__(self, *args, **kwargs):
644+
def __init__(self, **kwargs):
645645
super(CameraDevice, self).__init__(**kwargs)
646646
# A list of readout mode descriptions.
647647
self._readout_modes = ['default']
@@ -880,8 +880,8 @@ class SerialDeviceMixIn(object):
880880
"""
881881
__metaclass__ = abc.ABCMeta
882882

883-
def __init__(self, *args, **kwargs):
884-
super(SerialDeviceMixIn, self).__init__(*args, **kwargs)
883+
def __init__(self, **kwargs):
884+
super(SerialDeviceMixIn, self).__init__(**kwargs)
885885
## TODO: We should probably construct the connection here but
886886
## the Serial constructor takes a lot of arguments, and
887887
## it becomes tricky to separate those from arguments to
@@ -948,7 +948,7 @@ class DeformableMirror(Device):
948948
__metaclass__ = abc.ABCMeta
949949

950950
@abc.abstractmethod
951-
def __init__(self, *args, **kwargs):
951+
def __init__(self, **kwargs):
952952
"""Constructor.
953953
954954
Subclasses must define the following properties during
@@ -960,7 +960,7 @@ def __init__(self, *args, **kwargs):
960960
`_pattern_idx` are initialized to None to support the queueing
961961
of patterns and software triggering.
962962
"""
963-
super(DeformableMirror, self).__init__(*args, **kwargs)
963+
super(DeformableMirror, self).__init__(**kwargs)
964964

965965
self._patterns = None
966966
self._patterns_idx = None
@@ -1030,8 +1030,8 @@ class LaserDevice(Device):
10301030
__metaclass__ = abc.ABCMeta
10311031

10321032
@abc.abstractmethod
1033-
def __init__(self, *args, **kwargs):
1034-
super(LaserDevice, self).__init__(*args, **kwargs)
1033+
def __init__(self, **kwargs):
1034+
super(LaserDevice, self).__init__(**kwargs)
10351035
self._set_point = None
10361036

10371037
@abc.abstractmethod
@@ -1090,8 +1090,8 @@ def set_power_mw(self, mw):
10901090
class FilterWheelBase(Device):
10911091
__metaclass__ = abc.ABCMeta
10921092

1093-
def __init__(self, *args, filters=[], positions=0, **kwargs):
1094-
super(FilterWheelBase, self).__init__(*args, **kwargs)
1093+
def __init__(self, filters=[], positions=0, **kwargs):
1094+
super(FilterWheelBase, self).__init__(**kwargs)
10951095
if isinstance(filters, dict):
10961096
self._filters = filters
10971097
else:

microscope/filterwheels/aurox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class Clarity(microscope.devices.FilterWheelBase):
8686
__GETSERIAL: 4,
8787
__FULLSTAT: 10}
8888

89-
def __init__(self, *args, **kwargs):
90-
super().__init__(*args, **kwargs)
89+
def __init__(self, **kwargs):
90+
super().__init__(**kwargs)
9191
from threading import Lock
9292
self._lock = Lock()
9393
self._hid = None

microscope/lasers/cobolt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525

2626
class CoboltLaser(devices.SerialDeviceMixIn, devices.LaserDevice):
27-
def __init__(self, com=None, baud=115200, timeout=0.01, *args, **kwargs):
28-
super(CoboltLaser, self).__init__(*args, **kwargs)
27+
def __init__(self, com=None, baud=115200, timeout=0.01, **kwargs):
28+
super(CoboltLaser, self).__init__(**kwargs)
2929
self.connection = serial.Serial(port = com,
3030
baudrate = baud, timeout = timeout,
3131
stopbits = serial.STOPBITS_ONE,

microscope/lasers/deepstar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from microscope import devices
2525

2626
class DeepstarLaser(devices.SerialDeviceMixIn, devices.LaserDevice):
27-
def __init__(self, com, baud=9600, timeout=2.0, *args, **kwargs):
28-
super(DeepstarLaser, self).__init__(*args, **kwargs)
27+
def __init__(self, com, baud=9600, timeout=2.0, **kwargs):
28+
super(DeepstarLaser, self).__init__(**kwargs)
2929
self.connection = serial.Serial(port = com,
3030
baudrate = baud, timeout = timeout,
3131
stopbits = serial.STOPBITS_ONE,

microscope/lasers/sapphire.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ class SapphireLaser(devices.SerialDeviceMixIn, devices.LaserDevice):
3535
b'6': 'Error',
3636
}
3737

38-
def __init__(self, com=None, baud=19200, timeout=0.5, *args, **kwargs):
38+
def __init__(self, com=None, baud=19200, timeout=0.5, **kwargs):
3939
# laser controller must run at 19200 baud, 8+1 bits,
4040
# no parity or flow control
4141
# timeout is recomended to be over 0.5
42-
super(SapphireLaser, self).__init__(*args, **kwargs)
42+
super(SapphireLaser, self).__init__(**kwargs)
4343
self.connection = serial.Serial(port = com,
4444
baudrate = baud, timeout = timeout,
4545
stopbits = serial.STOPBITS_ONE,

microscope/mirror/alpao.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ def _raise_if_error(self, status, exception_cls=Exception):
9595
raise exception_cls(msg)
9696

9797

98-
def __init__(self, serial_number, *args, **kwargs):
98+
def __init__(self, serial_number, **kwargs):
9999
"""
100100
Parameters
101101
----------
102102
serial_number: string
103103
The serial number of the deformable mirror, something like "BIL103".
104104
"""
105-
super(AlpaoDeformableMirror, self).__init__(*args, **kwargs)
105+
super(AlpaoDeformableMirror, self).__init__(**kwargs)
106106

107107
## We need to constantly check for errors and need a buffer to
108108
## have the message written to. To avoid creating a new buffer

microscope/mirror/bmc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232

3333
class BMCDeformableMirror(DeformableMirror):
34-
def __init__(self, serial_number, *args, **kwargs):
35-
super(BMCDeformableMirror, self).__init__(*args, **kwargs)
34+
def __init__(self, serial_number, **kwargs):
35+
super(BMCDeformableMirror, self).__init__(**kwargs)
3636
self._dm = BMC.DM()
3737

3838
if __debug__:

0 commit comments

Comments
 (0)