Skip to content

Use raw strings to avoid invalid escape sequences

jn requested to merge jn/busdisplay:syntax into master

Recent versions of Python (tested with 3.12) print the following syntax warnings. To avoid them, use the r'' raw string syntax in strings that (may) contain a backslash that is not supposed to be an escape sequence.

$ ./busdisplay.py
busdisplay.py:74: SyntaxWarning: invalid escape sequence '\-'
  sp+' _|--/~\------/~\-+  |__________________| |__________________| |__________________|'+sp,
busdisplay.py:75: SyntaxWarning: invalid escape sequence '\_'
  sp+'//// \_/      \_/       (O)        (O)       (O)        (O)     (O)        (O)sp   '+sp
busdisplay.py:87: SyntaxWarning: invalid escape sequence '\s'
  sp = re.split('\s+|(?=\()|(?<=\))', text)
busdisplay.py:296: SyntaxWarning: invalid escape sequence '\_'
  self.block.set_rows([(None, 'K1', 'Zyge', '¯\_(ü)_/¯')])

Closes: #7

Edited by jn

Merge request reports