microscope-cockpit / cockpit

Cockpit is a microscope graphical user interface. It is a flexible and easy to extend platform aimed at life scientists using bespoke microscopes.
https://microscope-cockpit.org
GNU General Public License v3.0
35 stars 26 forks source link

Python 3.12 doesn't like \ in strings. #893

Closed iandobbie closed 1 month ago

iandobbie commented 1 month ago

So we have a few regexps in the code that contain \ escape sequences that are now syntax errors. I think these just need to be replaced with raw strings.

/Users/ID/src/cockpit/cockpit/devices/microscopeDevice.py:369: SyntaxWarning: invalid escape sequence '\s'
  self.cameras = re.split('[,;]\s*', cdefs)
/Users/ID/src/cockpit/cockpit/devices/microscopeDevice.py:376: SyntaxWarning: invalid escape sequence '\s'
  self.lights = re.split('[,;]\s*', ldefs)
/Users/ID/src/cockpit/cockpit/devices/microscopeDevice.py:386: SyntaxWarning: invalid escape sequence '\s'
carandraug commented 1 month ago

You are right. Apparently, this has been happening since python 3.6 but it was a DeprecationWarning. Python 3.12 bumped it to SyntaxWarning with the goal of bumping it to SyntaxError later. See python 3.12 changes:

  • A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+.\d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+.\d+")). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.)
iandobbie commented 1 month ago

Simple fix to just make the regexps raw strings. Pushed above and closing as fixed.