Skip to content

Commit 94f337d

Browse files
authored
Minor linting nitpicks and Python 2 removal (#441)
* Removed py2 handling in import_eds * Made file open more robust in import_eds * Additional whitespace removals
1 parent 24df6e8 commit 94f337d

File tree

8 files changed

+25
-29
lines changed

8 files changed

+25
-29
lines changed

canopen/lss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,12 @@ def send_identify_non_configured_remote_slave(self):
239239
self.__send_command(message)
240240

241241
def fast_scan(self):
242-
"""This command sends a series of fastscan message
242+
"""This command sends a series of fastscan message
243243
to find unconfigured slave with lowest number of LSS idenities
244244
245245
:return:
246246
True if a slave is found.
247-
False if there is no candidate.
247+
False if there is no candidate.
248248
list is the LSS identities [vendor_id, product_code, revision_number, serial_number]
249249
:rtype: bool, list
250250
"""

canopen/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def __init__(
298298
bus,
299299
remote: bool = False,
300300
):
301-
"""
301+
"""
302302
:param can_id:
303303
CAN-ID of the message
304304
:param data:

canopen/objectdictionary/eds.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
def import_eds(source, node_id):
2020
eds = RawConfigParser(inline_comment_prefixes=(';',))
2121
eds.optionxform = str
22-
if hasattr(source, "read"):
23-
fp = source
24-
else:
25-
fp = open(source)
22+
opened_here = False
2623
try:
27-
# Python 3
24+
if hasattr(source, "read"):
25+
fp = source
26+
else:
27+
fp = open(source)
28+
opened_here = True
2829
eds.read_file(fp)
29-
except AttributeError:
30-
# Python 2
31-
eds.readfp(fp)
3230
finally:
3331
# Only close object if opened in this fn
34-
if not hasattr(source, "read"):
32+
if opened_here:
3533
fp.close()
3634

3735
od = ObjectDictionary()
@@ -208,7 +206,7 @@ def _calc_bit_length(data_type):
208206
def _signed_int_from_hex(hex_str, bit_length):
209207
number = int(hex_str, 0)
210208
max_value = (1 << (bit_length - 1)) - 1
211-
209+
212210
if number > max_value:
213211
return number - (1 << bit_length)
214212
else:

canopen/sdo/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def request_response(self, sdo_request):
8686
except SdoCommunicationError as e:
8787
retries_left -= 1
8888
if not retries_left:
89-
self.abort(0x5040000)
89+
self.abort(0x5040000)
9090
raise
9191
logger.warning(str(e))
9292

@@ -463,7 +463,7 @@ def __init__(self, sdo_client, index, subindex=0, request_crc_support=True):
463463
:param int subindex:
464464
Object dictionary sub-index to read from.
465465
:param bool request_crc_support:
466-
If crc calculation should be requested when using block transfer
466+
If crc calculation should be requested when using block transfer
467467
"""
468468
self._done = False
469469
self.sdo_client = sdo_client
@@ -628,7 +628,7 @@ def __init__(self, sdo_client, index, subindex=0, size=None, request_crc_support
628628
:param int size:
629629
Size of data in number of bytes if known in advance.
630630
:param bool request_crc_support:
631-
If crc calculation should be requested when using block transfer
631+
If crc calculation should be requested when using block transfer
632632
"""
633633
self.sdo_client = sdo_client
634634
self.size = size
@@ -755,7 +755,7 @@ def _block_ack(self):
755755
logger.debug("Server requested a block size of %d", blksize)
756756
self._blksize = blksize
757757
self._seqno = 0
758-
758+
759759
def _retransmit(self, ackseq, blksize):
760760
"""Retransmit the failed block"""
761761
logger.info(("%d of %d sequences were received. "

canopen/sdo/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def download(
203203
data: bytes,
204204
force_segment: bool = False,
205205
):
206-
"""May be called to make a write operation without an Object Dictionary.
206+
"""May be called to make a write operation without an Object Dictionary.
207207
208208
:param index:
209209
Index of object to write.

canopen/variable.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ def raw(self) -> Union[int, bool, float, str, bytes]:
6161
+---------------------------+----------------------------+
6262
| REALxx | :class:`float` |
6363
+---------------------------+----------------------------+
64-
| VISIBLE_STRING | :class:`str` / |
65-
| | ``unicode`` (Python 2) |
64+
| VISIBLE_STRING | :class:`str` |
6665
+---------------------------+----------------------------+
67-
| UNICODE_STRING | :class:`str` / |
68-
| | ``unicode`` (Python 2) |
66+
| UNICODE_STRING | :class:`str` |
6967
+---------------------------+----------------------------+
7068
| OCTET_STRING | :class:`bytes` |
7169
+---------------------------+----------------------------+

examples/eds/e35.eds

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,7 +5083,7 @@ DefaultValue=0
50835083
PDOMapping=0x0
50845084

50855085
[2C01subB]
5086-
ParameterName=Accumulator divide register
5086+
ParameterName=Accumulator divide register
50875087
ObjectType=0x7
50885088
DataType=0x0004
50895089
AccessType=wo
@@ -5099,7 +5099,7 @@ DefaultValue=0
50995099
PDOMapping=0x0
51005100

51015101
[2C01subD]
5102-
ParameterName=Accumulator multiply register
5102+
ParameterName=Accumulator multiply register
51035103
ObjectType=0x7
51045104
DataType=0x0004
51055105
AccessType=wo
@@ -5131,15 +5131,15 @@ DefaultValue=0
51315131
PDOMapping=0x0
51325132

51335133
[2C01sub11]
5134-
ParameterName=Shift left accumulator by register
5134+
ParameterName=Shift left accumulator by register
51355135
ObjectType=0x7
51365136
DataType=0x0004
51375137
AccessType=wo
51385138
DefaultValue=0
51395139
PDOMapping=0x0
51405140

51415141
[2C01sub12]
5142-
ParameterName=Shift right accumulator by register
5142+
ParameterName=Shift right accumulator by register
51435143
ObjectType=0x7
51445144
DataType=0x0004
51455145
AccessType=wo
@@ -7835,7 +7835,7 @@ PDOMapping=0x0
78357835
ParameterValue=0x2
78367836

78377837
[1A02sub1]
7838-
ParameterName=Position Actual Value
7838+
ParameterName=Position Actual Value
78397839
ObjectType=0x7
78407840
DataType=0x0007
78417841
AccessType=rw

test/test_eds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def test_dummy_variable(self):
157157
def test_dummy_variable_undefined(self):
158158
with self.assertRaises(KeyError):
159159
var_undef = self.od['Dummy0001']
160-
160+
161161
def test_reading_factor(self):
162162
var = self.od['EDS file extensions']['FactorAndDescription']
163163
self.assertEqual(var.factor, 0.1)
@@ -167,7 +167,7 @@ def test_reading_factor(self):
167167
self.assertEqual(var2.description, '')
168168
self.assertEqual(var2.factor, 1)
169169
self.assertEqual(var2.unit, '')
170-
170+
171171

172172

173173
def test_comments(self):

0 commit comments

Comments
 (0)