Skip to content

Commit

Permalink
Fix issue with multiline f-string concatenation in Micro|CircuitPython.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haydenroche5 committed Oct 17, 2023
1 parent 22885ce commit 1a57fdf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ flake8:
# F403 'from module import *' used; unable to detect undefined names https://www.flake8rules.com/rules/F403.html
# W503 Line break occurred before a binary operator https://www.flake8rules.com/rules/W503.html
# E501 Line too long (>79 characters) https://www.flake8rules.com/rules/E501.html
${PYTHON} -m flake8 test/ notecard/ examples/ mpy_board/ --count --ignore=E722,F401,F403,W503,E501 --show-source --statistics
${PYTHON} -m flake8 test/ notecard/ examples/ mpy_board/ --count --ignore=E722,F401,F403,W503,E501,E502 --show-source --statistics

coverage:
${RUN_VENV_ACTIVATE}
Expand Down
60 changes: 30 additions & 30 deletions notecard/notecard.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def _crc_error(self, rsp_bytes):

if seq_number != expected_seq_number:
if self._debug:
print(('Sequence number mismatch. Expected '
f'{expected_seq_number}, received {seq_number}.'))
print('Sequence number mismatch. Expected ' + \
f'{expected_seq_number}, received {seq_number}.')
return True
elif crc != computed_crc:
if self._debug:
Expand Down Expand Up @@ -245,8 +245,8 @@ def _transaction_timeout_seconds(self, req):
elif 'cmd' in req:
req_key = 'cmd'
else:
raise Exception(('Malformed request. Missing \'req\' or \'cmd\' '
f'field: {req}.'))
raise Exception('Malformed request. Missing \'req\' or \'cmd\' ' + \
f'field: {req}.')

if req[req_key] == 'note.add':
if 'milliseconds' in req:
Expand Down Expand Up @@ -328,17 +328,17 @@ def Transaction(self, req, lock=True):
if 'err' in rsp_json:
if '{io}' in rsp_json['err']:
if self._debug:
print(('Response has error field indicating I/O'
f' error: {rsp_json}'))
print('Response has error field indicating ' + \
f'I/O error: {rsp_json}')

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

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

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

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

if not something_found:
if self._debug:
print(('Notecard not responding to newline during '
'reset.'))
print('Notecard not responding to newline during ' + \
'reset.')

elif non_control_char_found:
if self._debug:
print(('Received non-control characters from the '
'Notecard during reset.'))
print('Received non-control characters from the ' + \
'Notecard during reset.')
else:
# If all we got back is newlines, we're in sync with the
# Notecard.
Expand Down Expand Up @@ -575,9 +575,9 @@ def __init__(self, uart_id, debug=False):
if hasattr(self.uart, 'in_waiting'):
self._available = self._available_default
else:
raise NotImplementedError(('Serial communications with the '
'Notecard are not supported for this'
' platform.'))
raise NotImplementedError('Serial communications with the ' + \
'Notecard are not supported for ' + \
' this platform.')

self.Reset()

Expand Down Expand Up @@ -610,9 +610,9 @@ def _read(self, length):
data = read_buf[2:]

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

return available, data

Expand Down Expand Up @@ -653,8 +653,8 @@ def receive(self, timeout_secs=CARD_INTRA_TRANSACTION_TIMEOUT_SEC,
break

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

if delay:
time.sleep(0.05)
Expand Down Expand Up @@ -708,8 +708,8 @@ def _transact(self, req_bytes, rsp_expected,
available, _ = self._read(0)

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

return self.receive()

Expand Down Expand Up @@ -768,13 +768,13 @@ def Reset(self):

if not something_found:
if self._debug:
print(('Notecard not responding to newline during '
'reset.'))
print('Notecard not responding to newline during ' + \
'reset.')
time.sleep(.005)
elif non_control_char_found:
if self._debug:
print(('Received non-control characters from the '
'Notecard during reset.'))
print('Received non-control characters from the ' + \
'Notecard during reset.')
else:
# If all we got back is newlines, we're in sync with the
# Notecard.
Expand Down

0 comments on commit 1a57fdf

Please sign in to comment.