Skip to content

Commit 1a57fdf

Browse files
committed
Fix issue with multiline f-string concatenation in Micro|CircuitPython.
See https://forum.micropython.org/viewtopic.php?f=2&t=11114. I also went ahead and changed to the new format for multiline strings that don't contain f-strings.
1 parent 22885ce commit 1a57fdf

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ flake8:
2929
# F403 'from module import *' used; unable to detect undefined names https://www.flake8rules.com/rules/F403.html
3030
# W503 Line break occurred before a binary operator https://www.flake8rules.com/rules/W503.html
3131
# E501 Line too long (>79 characters) https://www.flake8rules.com/rules/E501.html
32-
${PYTHON} -m flake8 test/ notecard/ examples/ mpy_board/ --count --ignore=E722,F401,F403,W503,E501 --show-source --statistics
32+
${PYTHON} -m flake8 test/ notecard/ examples/ mpy_board/ --count --ignore=E722,F401,F403,W503,E501,E502 --show-source --statistics
3333

3434
coverage:
3535
${RUN_VENV_ACTIVATE}

notecard/notecard.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ def _crc_error(self, rsp_bytes):
184184

185185
if seq_number != expected_seq_number:
186186
if self._debug:
187-
print(('Sequence number mismatch. Expected '
188-
f'{expected_seq_number}, received {seq_number}.'))
187+
print('Sequence number mismatch. Expected ' + \
188+
f'{expected_seq_number}, received {seq_number}.')
189189
return True
190190
elif crc != computed_crc:
191191
if self._debug:
@@ -245,8 +245,8 @@ def _transaction_timeout_seconds(self, req):
245245
elif 'cmd' in req:
246246
req_key = 'cmd'
247247
else:
248-
raise Exception(('Malformed request. Missing \'req\' or \'cmd\' '
249-
f'field: {req}.'))
248+
raise Exception('Malformed request. Missing \'req\' or \'cmd\' ' + \
249+
f'field: {req}.')
250250

251251
if req[req_key] == 'note.add':
252252
if 'milliseconds' in req:
@@ -328,17 +328,17 @@ def Transaction(self, req, lock=True):
328328
if 'err' in rsp_json:
329329
if '{io}' in rsp_json['err']:
330330
if self._debug:
331-
print(('Response has error field indicating I/O'
332-
f' error: {rsp_json}'))
331+
print('Response has error field indicating ' + \
332+
f'I/O error: {rsp_json}')
333333

334334
error = True
335335
retries_left -= 1
336336
time.sleep(0.5)
337337
continue
338338
elif '{bad-bin}' in rsp_json['err']:
339339
if self._debug:
340-
print(('Response has error field indicating '
341-
f'binary I/O error: {rsp_json}'))
340+
print('Response has error field indicating ' + \
341+
f'binary I/O error: {rsp_json}')
342342
print('Not eligible for retry.')
343343

344344
error = True
@@ -415,8 +415,8 @@ def _transact(self, req_bytes, rsp_expected,
415415
start = start_timeout()
416416
while not self._available():
417417
if timeout_secs != 0 and has_timed_out(start, timeout_secs):
418-
raise Exception(('Timed out while querying Notecard for '
419-
'available data.'))
418+
raise Exception('Timed out while querying Notecard for ' + \
419+
'available data.')
420420

421421
# Delay for 10 ms before checking for available data again.
422422
time.sleep(.01)
@@ -433,8 +433,8 @@ def receive(self, timeout_secs=CARD_INTRA_TRANSACTION_TIMEOUT_SEC,
433433
while not received_newline:
434434
while not self._available():
435435
if timeout_secs != 0 and has_timed_out(start, timeout_secs):
436-
raise Exception(('Timed out waiting to receive data from '
437-
'Notecard.'))
436+
raise Exception('Timed out waiting to receive data from' + \
437+
' Notecard.')
438438

439439
# Sleep while awaiting the first byte (lazy). After the first
440440
# byte, start to spin for the remaining bytes (greedy).
@@ -521,13 +521,13 @@ def Reset(self):
521521

522522
if not something_found:
523523
if self._debug:
524-
print(('Notecard not responding to newline during '
525-
'reset.'))
524+
print('Notecard not responding to newline during ' + \
525+
'reset.')
526526

527527
elif non_control_char_found:
528528
if self._debug:
529-
print(('Received non-control characters from the '
530-
'Notecard during reset.'))
529+
print('Received non-control characters from the ' + \
530+
'Notecard during reset.')
531531
else:
532532
# If all we got back is newlines, we're in sync with the
533533
# Notecard.
@@ -575,9 +575,9 @@ def __init__(self, uart_id, debug=False):
575575
if hasattr(self.uart, 'in_waiting'):
576576
self._available = self._available_default
577577
else:
578-
raise NotImplementedError(('Serial communications with the '
579-
'Notecard are not supported for this'
580-
' platform.'))
578+
raise NotImplementedError('Serial communications with the ' + \
579+
'Notecard are not supported for ' + \
580+
' this platform.')
581581

582582
self.Reset()
583583

@@ -610,9 +610,9 @@ def _read(self, length):
610610
data = read_buf[2:]
611611

612612
if len(data) != data_len:
613-
raise Exception(('Serial-over-I2C error: reported data length '
614-
f'({data_len}) differs from actual data length'
615-
f' ({len(data)}).'))
613+
raise Exception('Serial-over-I2C error: reported data length ' + \
614+
f'({data_len}) differs from actual data length' + \
615+
f' ({len(data)}).')
616616

617617
return available, data
618618

@@ -653,8 +653,8 @@ def receive(self, timeout_secs=CARD_INTRA_TRANSACTION_TIMEOUT_SEC,
653653
break
654654

655655
if timeout_secs != 0 and has_timed_out(start, timeout_secs):
656-
raise Exception(('Timed out while reading data from the '
657-
'Notecard.'))
656+
raise Exception('Timed out while reading data from the ' + \
657+
'Notecard.')
658658

659659
if delay:
660660
time.sleep(0.05)
@@ -708,8 +708,8 @@ def _transact(self, req_bytes, rsp_expected,
708708
available, _ = self._read(0)
709709

710710
if timeout_secs != 0 and has_timed_out(start, timeout_secs):
711-
raise Exception(('Timed out while querying Notecard for '
712-
'available data.'))
711+
raise Exception('Timed out while querying Notecard for ' + \
712+
'available data.')
713713

714714
return self.receive()
715715

@@ -768,13 +768,13 @@ def Reset(self):
768768

769769
if not something_found:
770770
if self._debug:
771-
print(('Notecard not responding to newline during '
772-
'reset.'))
771+
print('Notecard not responding to newline during ' + \
772+
'reset.')
773773
time.sleep(.005)
774774
elif non_control_char_found:
775775
if self._debug:
776-
print(('Received non-control characters from the '
777-
'Notecard during reset.'))
776+
print('Received non-control characters from the ' + \
777+
'Notecard during reset.')
778778
else:
779779
# If all we got back is newlines, we're in sync with the
780780
# Notecard.

0 commit comments

Comments
 (0)