Skip to content

Commit d03749a

Browse files
authored
Add flake8-comprehensions. (#892)
1 parent 51908c1 commit d03749a

21 files changed

+44
-36
lines changed

TODO_add_checks

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
2) new checks
44
- flake8 addons:
55
pycodestyle
6-
pyflakes
76
pydocstyle
8-
flake8-comprehensions
97

108
- prettier
119
- mypy

examples/contrib/remote_server_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ def __extract_result(self, f_code, result): # pylint: disable=no-self-use
118118
:param result: The resulting data
119119
"""
120120
if not result.isError():
121-
if f_code in set(['d', 'c']):
121+
if f_code in {'d', 'c'}:
122122
return result.bits
123-
if f_code in set(['h', 'i']):
123+
if f_code in {'h', 'i'}:
124124
return result.registers
125125
return None
126126
return result

pymodbus/datastore/remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ def __extract_result(self, fc_as_hex, result): # pylint: disable=no-self-use
104104
TODO make this consistent (values?)
105105
"""
106106
if not result.isError():
107-
if fc_as_hex in set(['d', 'c']):
107+
if fc_as_hex in {'d', 'c'}:
108108
return result.bits
109-
if fc_as_hex in set(['h', 'i']):
109+
if fc_as_hex in {'h', 'i'}:
110110
return result.registers
111111
else:
112112
return result

pymodbus/datastore/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def setValues(self, address, values, use_as_default=False):
293293
:param use_as_default: Use the values as default
294294
"""
295295
if isinstance(values, dict):
296-
new_offsets = list(set(list(values.keys())) - set(list(self.values.keys())))
296+
new_offsets = list(set(list(values.keys())) - set(list(self.values.keys()))) # noqa: C414
297297
if new_offsets and not self.mutable:
298298
raise ParameterException(f"Offsets {new_offsets} not in range")
299299
self._process_values(values)

pymodbus/device.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def __gets(cls, identity, object_ids): # NOSONAR pylint: disable=unused-private
333333
:param object_ids: The specific object ids to read
334334
:returns: The requested data (id, length, value)
335335
"""
336-
return dict((oid, identity[oid]) for oid in object_ids if identity[oid])
336+
return {oid: identity[oid] for oid in object_ids if identity[oid]}
337337

338338

339339
# ---------------------------------------------------------------------------#
@@ -408,7 +408,7 @@ class ModbusCountersHandler:
408408
.. note:: I threw the event counter in here for convenience
409409
"""
410410

411-
__data = dict([(i, 0x0000) for i in range(9)]) # pylint: disable=consider-using-dict-comprehension
411+
__data = {i: 0x0000 for i in range(9)} # pylint: disable=consider-using-dict-comprehension
412412
__names = [
413413
'BusMessage',
414414
'BusCommunicationError',
@@ -441,7 +441,7 @@ def update(self, values):
441441

442442
def reset(self):
443443
"""Clear all of the system counters."""
444-
self.__data = dict([(i, 0x0000) for i in range(9)]) # pylint: disable=consider-using-dict-comprehension
444+
self.__data = {i: 0x0000 for i in range(9)} # pylint: disable=consider-using-dict-comprehension
445445

446446
def summary(self):
447447
"""Return a summary of the counters current status.
@@ -564,7 +564,7 @@ def _setMode(self, mode): # pylint: disable=invalid-name
564564
565565
:param mode: The data transfer method in (RTU, ASCII)
566566
"""
567-
if mode in set(['ASCII', 'RTU']):
567+
if mode in {'ASCII', 'RTU'}:
568568
self.__mode = mode # pylint: disable=unused-private-member
569569

570570
Mode = property(lambda s: s.__mode, _setMode)

pymodbus/factory.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ class ServerDecoder(IModbusDecoder):
165165

166166
def __init__(self):
167167
"""Initialize the client lookup tables."""
168-
functions = set(f.function_code for f in self.__function_table)
169-
self.__lookup = dict( # pylint: disable=consider-using-dict-comprehension
170-
[(f.function_code, f) for f in self.__function_table])
171-
self.__sub_lookup = dict((f, {}) for f in functions)
168+
functions = {f.function_code for f in self.__function_table}
169+
self.__lookup = { # pylint: disable=consider-using-dict-comprehension
170+
f.function_code: f for f in self.__function_table}
171+
self.__sub_lookup = {f: {} for f in functions}
172172
for f in self.__sub_function_table:
173173
self.__sub_lookup[f.function_code][f.sub_function_code] = f
174174

@@ -295,10 +295,10 @@ class ClientDecoder(IModbusDecoder):
295295

296296
def __init__(self):
297297
"""Initialize the client lookup tables."""
298-
functions = set(f.function_code for f in self.__function_table)
299-
self.__lookup = dict([(f.function_code, f) # pylint: disable=consider-using-dict-comprehension
300-
for f in self.__function_table])
301-
self.__sub_lookup = dict((f, {}) for f in functions)
298+
functions = {f.function_code for f in self.__function_table}
299+
self.__lookup = {f.function_code: f # pylint: disable=consider-using-dict-comprehension
300+
for f in self.__function_table}
301+
self.__sub_lookup = {f: {} for f in functions}
302302
for f in self.__sub_function_table:
303303
self.__sub_lookup[f.function_code][f.sub_function_code] = f
304304

pymodbus/framer/ascii_framer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def decode_data(self, data): # pylint: disable=no-self-use
5555
if len(data) > 1:
5656
uid = int(data[1:3], 16)
5757
fcode = int(data[3:5], 16)
58-
return dict(unit=uid, fcode=fcode)
58+
return {'unit': uid, 'fcode': fcode}
5959
return {}
6060

6161
def checkFrame(self):

pymodbus/framer/binary_framer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def decode_data(self, data):
6363
if len(data) > self._hsize:
6464
uid = struct.unpack('>B', data[1:2])[0]
6565
fcode = struct.unpack('>B', data[2:3])[0]
66-
return dict(unit=uid, fcode=fcode)
66+
return {'unit': uid, 'fcode': fcode}
6767
return {}
6868

6969
def checkFrame(self):

pymodbus/framer/rtu_framer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def decode_data(self, data):
7474
if len(data) > self._hsize:
7575
uid = int(data[0])
7676
fcode = int(data[1])
77-
return dict(unit=uid, fcode=fcode)
77+
return {'unit': uid, 'fcode': fcode}
7878
return {}
7979

8080
def checkFrame(self):

pymodbus/framer/socket_framer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ def decode_data(self, data):
124124
if len(data) > self._hsize:
125125
tid, pid, length, uid, fcode = struct.unpack(SOCKET_FRAME_HEADER,
126126
data[0:self._hsize + 1])
127-
return dict(tid=tid, pid=pid, length=length, unit=uid, fcode=fcode)
127+
return {
128+
'tid': tid,
129+
'pid': pid,
130+
'length': length,
131+
'unit': uid,
132+
'fcode': fcode,
133+
}
128134
return {}
129135

130136
def processIncomingPacket(self, data, callback, unit, **kwargs): # NOSONAR pylint: disable=arguments-differ

0 commit comments

Comments
 (0)