Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
iandobbie opened this issue Jun 8, 2024 · 3 comments
Closed

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

iandobbie opened this issue Jun 8, 2024 · 3 comments

Comments

@iandobbie
Copy link
Collaborator

iandobbie commented Jun 8, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator Author

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

@carandraug
Copy link
Collaborator

Seems like we missed some regexps that needed to be using raw strings. I just added them and also decided to use it on all regexps, even those that didn't need it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants