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 and 3.13 emit "SyntaxWarning: invalid escape sequence" #12

Open
hacklschorsch opened this issue Jan 16, 2025 · 1 comment · May be fixed by #13
Open

Python 3.12 and 3.13 emit "SyntaxWarning: invalid escape sequence" #12

hacklschorsch opened this issue Jan 16, 2025 · 1 comment · May be fixed by #13

Comments

@hacklschorsch
Copy link

hacklschorsch commented Jan 16, 2025

Similar to https://tahoe-lafs.org/trac/tahoe-lafs/ticket/4158 and tahoe-lafs/tahoe-lafs#1427:

From https://stackoverflow.com/a/77531416/1181063:

Back in Python 3.6, using invalid escape sequences in string literals was deprecated (bpo-27364). Since then, attempting to use an invalid escape sequence has emitted a DeprecationWarning. This can often go unnoticed if you don't run Python with warnings enabled. DeprecationWarnings are silenced by default.

Python 3.12 upgraded the DeprecationWarning to a SyntaxWarning. SyntaxWarnings are emitted by the compiler when the code is parsed, not when it's being run, so they cannot be ignored using a runtime warning filter. Unlike DeprecationWarnings, SyntaxWarnings are displayed by default, which is why you're seeing it now. This increase in visibility was intentional. In a future version of Python, using invalid escape sequences in string literals is planned to eventually become a hard SyntaxError.

From the Tahoe-LAFS CI job for the Debian Trixie package:

Setting up python3-pyutil (3.3.2-3) ...
/usr/lib/python3/dist-packages/pyutil/iputil.py:180: SyntaxWarning: invalid escape sequence '\s'
  _win32_re = re.compile('^\s*\d+\.\d+\.\d+\.\d+\s.+\s(?P<address>\d+\.\d+\.\d+\.\d+)\s+(?P<metric>\d+)\s*$', flags=re.M|re.I|re.S)
/usr/lib/python3/dist-packages/pyutil/iputil.py:184: SyntaxWarning: invalid escape sequence '\s'
  _linux_re = re.compile('^\s*inet [a-zA-Z]*:?(?P<address>\d+\.\d+\.\d+\.\d+)\s.+$', flags=re.M|re.I|re.S)
/usr/lib/python3/dist-packages/pyutil/iputil.py:189: SyntaxWarning: invalid escape sequence '\s'
  _netbsd_re = re.compile('^\s+inet [a-zA-Z]*:?(?P<address>\d+\.\d+\.\d+\.\d+)\s.+$', flags=re.M|re.I|re.S)
/usr/lib/python3/dist-packages/pyutil/platformutil.py:6: SyntaxWarning: invalid escape sequence '\s'
  _distributor_id_cmdline_re = re.compile("(?:Distributor ID:)\s*(.*)", re.I)
/usr/lib/python3/dist-packages/pyutil/platformutil.py:7: SyntaxWarning: invalid escape sequence '\s'
  _release_cmdline_re = re.compile("(?:Release:)\s*(.*)", re.I)
/usr/lib/python3/dist-packages/pyutil/platformutil.py:9: SyntaxWarning: invalid escape sequence '\s'
  _distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I)
/usr/lib/python3/dist-packages/pyutil/platformutil.py:10: SyntaxWarning: invalid escape sequence '\s'
  _release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I)
/usr/lib/python3/dist-packages/pyutil/test/current/test_iputil.py:18: SyntaxWarning: invalid escape sequence '\.'
  DOTTED_QUAD_RE=re.compile("^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:82: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(any(x for x in d.values() if x is 8))
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:84: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(not any(x for x in d.values() if x is 7)) # The real 7 should have been ejected by the d[3] = 8.
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:86: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(any(x for x in d if x is 3))
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:95: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(any(x for x in d.values() if x is 8))
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:97: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(not any(x for x in d.values() if x is 7)) # The real 7 should have been ejected by the d[3] = 8.
/usr/lib/python3/dist-packages/pyutil/test/deprecated/test_dictutil.py:99: SyntaxWarning: "is" with 'int' literal. Did you mean "=="?
  _assert(any(x for x in d if x is 3))
/usr/lib/python3/dist-packages/pyutil/version_class.py:82: SyntaxWarning: invalid escape sequence '\d'
  VERSION_BASE_RE_STR="(\d+)(\.(\d+)(\.(\d+))?)?((a|b|c)(\d+))?(\.dev(\d+))?"
/usr/lib/python3/dist-packages/pyutil/version_class.py:83: SyntaxWarning: invalid escape sequence '\d'
  VERSION_SUFFIX_RE_STR="(-(\d+|r\d+)|.post\d+)?"
hacklschorsch added a commit to hacklschorsch/pyutil that referenced this issue Jan 16, 2025
@hacklschorsch hacklschorsch linked a pull request Jan 16, 2025 that will close this issue
@a-detiste
Copy link

The Debian maintainers would be happy that Python2 comptibility would be dropped & simplejson usage too ;-)

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

Successfully merging a pull request may close this issue.

2 participants