Skip to content

Commit 1b0dcce

Browse files
Remove several linter warnings
1 parent fa42a9a commit 1b0dcce

File tree

9 files changed

+77
-47
lines changed

9 files changed

+77
-47
lines changed

pystages/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,16 @@
2424
from .vector import Vector
2525
from .tic import Tic, TicDirection
2626
from .cncrouter import CNCRouter, CNCStatus
27+
28+
__all__ = [
29+
"Stage",
30+
"Corvus",
31+
"M3FS",
32+
"SMC100",
33+
"Autofocus",
34+
"Vector",
35+
"Tic",
36+
"TicDirection",
37+
"CNCRouter",
38+
"CNCStatus",
39+
]

pystages/cncrouter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ def receive_lines(self, until: str = "ok") -> List[str]:
224224
list.
225225
"""
226226
lines = []
227-
while (l := self.serial.readline().strip().decode()) != until:
228-
if len(l):
229-
lines.append(l)
227+
while (line := self.serial.readline().strip().decode()) != until:
228+
if len(line):
229+
lines.append(line)
230230
return lines
231231

232232
def receive(self) -> str:
@@ -276,7 +276,9 @@ def position(self) -> Vector:
276276
@position.setter
277277
def position(self, value: Vector):
278278
# To check dimension and range of the given value
279-
super(__class__, self.__class__).position.fset(self, value) # type: ignore
279+
pos_setter = Stage.position.fset
280+
assert pos_setter is not None
281+
pos_setter(self, value)
280282

281283
command = f"G0 X{value.x}"
282284
if len(value) > 1:

pystages/corvus.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ def position(self):
181181
@position.setter
182182
def position(self, value: Vector):
183183
# To check dimension and range of the given value
184-
super(__class__, self.__class__).position.fset(self, value) # type: ignore
184+
pos_setter = Stage.position.fset
185+
assert pos_setter is not None
186+
pos_setter(self, value)
187+
185188
self.send("3 setdim")
186189
self.send("{0} {1} {2} move".format(value.x, value.y, value.z))
187190

pystages/gui/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
from . import gui
2+
3+
4+
__all__ = ["gui"]

pystages/gui/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import sys
33
from PyQt6.QtGui import QIcon, QPalette, QColor
44
from .util import resource_path
5-
import sys
65
from .gui import StageWindow
76

87
app = QApplication(sys.argv)

pystages/m3fs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def position(self) -> Vector:
186186
@position.setter
187187
def position(self, value: Vector):
188188
# To check dimension and range of the given value
189-
super(__class__, self.__class__).position.fset(self, value) # type: ignore
189+
pos_setter = Stage.position.fset
190+
assert pos_setter is not None
191+
pos_setter(self, value)
190192

191193
val = round(value.x / self.resolution_um).to_bytes(4, "big", signed=True)
192194
self.command(M3FSCommand.MOVE_TO_TARGET, hexlify(val).decode())

pystages/smc100.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
# written by Olivier Hériveaux, Manuel San Pedro and Michaël Mouchous
1919

2020

21-
import serial
21+
import serial.serialutil
2222
import time
2323
from .vector import Vector
2424
from .exceptions import ProtocolError, ConnectionFailure
25-
from enum import Enum, IntFlag
25+
from enum import Enum, Flag
2626
from typing import Optional, List
2727
from .stage import Stage
2828

@@ -113,12 +113,12 @@ def response(self, address: Optional[int], command: str) -> str:
113113
"""
114114
query_string = f'{"" if address is None else address}{command}'
115115
res = self.receive()
116-
if res[: len(query_string)] != query_string:
116+
if res is None or res[: len(query_string)] != query_string:
117117
raise ProtocolError(query_string, res)
118118
return res[len(query_string) :]
119119

120120

121-
class State(Enum):
121+
class State(int, Enum):
122122
"""
123123
Possible controller states.
124124
The values in this enumeration corresponds to the values returned by the
@@ -148,7 +148,7 @@ class State(Enum):
148148
JOGGING_FROM_DISABLE = 0x47
149149

150150

151-
class Error(IntFlag):
151+
class Error(int, Flag):
152152
"""
153153
Information returned when querying positioner error.
154154
"""
@@ -171,8 +171,8 @@ class ErrorAndState:
171171
Information returned when querying positioner error and controller state.
172172
"""
173173

174-
state = None
175-
error = None
174+
state = State.NOT_REFERENCED_FROM_RESET
175+
error = Error.NO_ERROR
176176

177177
@property
178178
def is_referenced(self) -> bool:
@@ -183,41 +183,39 @@ def is_referenced(self) -> bool:
183183
raise RuntimeError("state not available")
184184
else:
185185
return not (
186-
(self.state.value >= State.NOT_REFERENCED_FROM_RESET.value)
187-
and (self.state.value <= State.NOT_REFERENCED_FROM_JOGGING.value)
186+
(self.state >= State.NOT_REFERENCED_FROM_RESET)
187+
and (self.state <= State.NOT_REFERENCED_FROM_JOGGING)
188188
)
189189

190190
@property
191191
def is_ready(self) -> bool:
192192
""":return: True if state is one of READY_x states."""
193-
return (self.state.value >= State.READY_FROM_HOMING.value) and (
194-
self.state.value <= State.READY_FROM_JOGGING.value
193+
return (self.state >= State.READY_FROM_HOMING) and (
194+
self.state <= State.READY_FROM_JOGGING
195195
)
196196

197197
@property
198198
def is_moving(self) -> bool:
199199
""":return: True if state is MOVING."""
200-
return self.state.value == State.MOVING.value
200+
return self.state == State.MOVING
201201

202202
@property
203203
def is_homing(self) -> bool:
204204
""":return: True if state is one of HOMING_x states."""
205-
return (self.state.value >= State.HOMING_RS232.value) and (
206-
self.state.value <= State.HOMING_SMCRC.value
207-
)
205+
return (self.state >= State.HOMING_RS232) and (self.state <= State.HOMING_SMCRC)
208206

209207
@property
210-
def is_jogging(self):
208+
def is_jogging(self) -> bool:
211209
""":return: True if state is one of JOGGING_x states."""
212-
return (self.state.value >= State.JOGGING_FROM_READY.value) and (
213-
self.state.value <= State.JOGGING_FROM_DISABLE.value
210+
return (self.state >= State.JOGGING_FROM_READY) and (
211+
self.state <= State.JOGGING_FROM_DISABLE
214212
)
215213

216214
@property
217-
def is_disabled(self):
215+
def is_disabled(self) -> bool:
218216
""":return: True if state is one of DISABLE_x states."""
219-
return (self.state.value >= State.DISABLE_FROM_READY.value) and (
220-
self.state.value <= State.DISABLE_FROM_JOGGING.value
217+
return (self.state >= State.DISABLE_FROM_READY) and (
218+
self.state <= State.DISABLE_FROM_JOGGING
221219
)
222220

223221

@@ -261,20 +259,24 @@ def position(self):
261259
# It is faster to send all the request and then get all the responses.
262260
# This reduces a lot the latency.
263261
for i, addr in enumerate(self.addresses):
264-
r = self.link.query(addr, "TP", lazy_res=False)
265-
val = float(r)
262+
res = self.link.query(addr, "TP", lazy_res=False)
263+
if res is None:
264+
raise ProtocolError("TP")
265+
val = float(res)
266266
result[i] = val
267267
return result
268268

269269
@position.setter
270270
def position(self, value: Vector):
271271
# To check dimension and range of the given value
272-
super(__class__, self.__class__).position.fset(self, value)
272+
pos_setter = Stage.position.fset
273+
assert pos_setter is not None
274+
pos_setter(self, value)
273275

274276
# Enable the motors
275277
self.is_disabled = False
276278
commands = []
277-
for position, addr in zip(value, self.addresses):
279+
for position, addr in zip(value.data, self.addresses):
278280
commands.append(f"{addr}PA{position:.5f}")
279281
self.link.send(None, "\r\n".join(commands))
280282

@@ -318,7 +320,7 @@ def get_error_and_state(self, addr: int):
318320
:return: Current error and state, in a ErrorAndState instance.
319321
"""
320322
res = self.link.query(addr, "TS")
321-
if len(res) != 6:
323+
if res is None or len(res) != 6:
322324
raise ProtocolError("TS", res)
323325
result = ErrorAndState()
324326
result.error = Error(int(res[:4], 16))
@@ -340,7 +342,10 @@ def controller_address(self, addr: int):
340342
"""
341343
Get controller's RS-485 address. int in [2, 31].
342344
"""
343-
return int(self.link.query(addr, "SA"))
345+
res = self.link.query(addr, "SA")
346+
if res is None:
347+
raise ProtocolError("SA")
348+
return int(res)
344349

345350
def set_controller_address(self, addr: int, value: int):
346351
"""

pystages/tic.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .exceptions import ConnectionFailure
2727

2828

29-
class TicVariable(Enum):
29+
class TicVariable(tuple[int, int, bool], Enum):
3030
"""
3131
Variables which can be read using GET_VARIABLE command.
3232
https://www.pololu.com/docs/0J71/7
@@ -74,7 +74,7 @@ class TicVariable(Enum):
7474
LAST_HP_DRIVER_ERRORS = (0xFF, 1, False)
7575

7676

77-
class TicCommand(Enum):
77+
class TicCommand(int, Enum):
7878
"""
7979
Command codes for Polulu Tic Stepper Motor Controller.
8080
https://www.pololu.com/docs/0J71/8
@@ -108,7 +108,7 @@ class TicCommand(Enum):
108108
START_BOOTLOADER = 0xFF
109109

110110

111-
class TicDirection(Enum):
111+
class TicDirection(int, Enum):
112112
"""Possible directions for homing"""
113113

114114
REVERSE = 0
@@ -140,7 +140,7 @@ def quick(self, command: TicCommand):
140140
141141
:param command: Command.
142142
"""
143-
self.dev.ctrl_transfer(0x40, command.value, 0, 0, 0)
143+
self.dev.ctrl_transfer(0x40, command, 0, 0, 0)
144144

145145
def write_7(self, command: TicCommand, data: int):
146146
"""
@@ -149,7 +149,7 @@ def write_7(self, command: TicCommand, data: int):
149149
:param command: Command.
150150
:param data: Value to be written.
151151
"""
152-
self.dev.ctrl_transfer(0x40, command.value, data, 0, 0)
152+
self.dev.ctrl_transfer(0x40, command, data, 0, 0)
153153

154154
def write_32(self, command: TicCommand, data: int):
155155
"""
@@ -158,7 +158,7 @@ def write_32(self, command: TicCommand, data: int):
158158
:param command: Command code.
159159
:param data: Value to be written.
160160
"""
161-
self.dev.ctrl_transfer(0x40, command.value, data & 0xFFFF, data >> 16, 0)
161+
self.dev.ctrl_transfer(0x40, command, data & 0xFFFF, data >> 16, 0)
162162

163163
def block_read(self, command: TicCommand, offset, length) -> bytes:
164164
"""
@@ -168,7 +168,7 @@ def block_read(self, command: TicCommand, offset, length) -> bytes:
168168
:param offset: Data offset.
169169
:param length: Data length.
170170
"""
171-
return bytes(self.dev.ctrl_transfer(0xC0, command.value, 0, offset, length))
171+
return bytes(self.dev.ctrl_transfer(0xC0, command, 0, offset, length))
172172

173173
def set_setting(self, command: TicCommand, data, offset):
174174
"""
@@ -178,7 +178,7 @@ def set_setting(self, command: TicCommand, data, offset):
178178
:param data: Value to be written.
179179
:param offset: Write offset.
180180
"""
181-
self.dev.ctrl_transfer(0x40, command.value, data, offset, 0)
181+
self.dev.ctrl_transfer(0x40, command, data, offset, 0)
182182

183183
def energize(self):
184184
self.quick(TicCommand.ENERGIZE)
@@ -207,7 +207,7 @@ def go_home(self, direction: TicDirection, wait: bool = True):
207207
:param wait: If True, wait for homing procedure end.
208208
"""
209209
self.exit_safe_start()
210-
self.write_7(TicCommand.GO_HOME, direction.value)
210+
self.write_7(TicCommand.GO_HOME, direction)
211211
if wait:
212212
while self.get_variable(TicVariable.MISC_FLAGS) & (1 << 4):
213213
self.exit_safe_start()
@@ -220,7 +220,7 @@ def set_target_velocity(self, velocity: int):
220220
self.write_32(TicCommand.SET_TARGET_VELOCITY, velocity)
221221

222222
def get_variable(self, variable: TicVariable) -> int:
223-
offset, length, signed = variable.value
223+
offset, length, signed = variable
224224
return int.from_bytes(
225225
self.block_read(TicCommand.GET_VARIABLE, offset, length),
226226
"little",
@@ -240,7 +240,10 @@ def position(self) -> Vector:
240240
@position.setter
241241
def position(self, value: Vector):
242242
# To check dimension and range of the given value
243-
super(__class__, self.__class__).position.fset(self, value) # type: ignore
243+
pos_setter = Stage.position.fset
244+
assert pos_setter is not None
245+
pos_setter(self, value)
246+
244247
self.target_position = value.x
245248
while self.position.x != value.x:
246249
sleep(self.poll_interval)

pystages/vector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __mul__(self, other: Union["Vector", int, float]):
163163

164164
result = Vector(dim=dim)
165165
if len(other) != dim:
166-
raise ValueError(f"Incorrect vector size")
166+
raise ValueError("Incorrect vector size")
167167
for i in range(dim):
168168
result[i] = self[i] * other[i]
169169
return result
@@ -173,7 +173,7 @@ def __truediv__(self, other):
173173
return self * (1.0 / other)
174174
else:
175175
raise TypeError(
176-
f"Incorrect type for second operand. int or float is expected."
176+
"Incorrect type for second operand. int or float is expected."
177177
)
178178

179179

0 commit comments

Comments
 (0)