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

SyntaxWarning with Python 3.12 #60

Closed
kitterma opened this issue Jan 5, 2024 · 2 comments
Closed

SyntaxWarning with Python 3.12 #60

kitterma opened this issue Jan 5, 2024 · 2 comments

Comments

@kitterma
Copy link

kitterma commented Jan 5, 2024

You can see from the following test log that there are now syntax warning with Python 3.12:

=== digparser.py
Testing: Python 3.12.1
/<<PKGBUILDDIR>>/dnslib/digparser.py:144: SyntaxWarning: invalid escape sequence '\d'
  m = re.search('version: (\d+),',edns)
/<<PKGBUILDDIR>>/dnslib/digparser.py:147: SyntaxWarning: invalid escape sequence '\s'
  m = re.search('flags:\s*(.*?);',edns)
/<<PKGBUILDDIR>>/dnslib/digparser.py:150: SyntaxWarning: invalid escape sequence '\d'
  m = re.search('udp: (\d+)',edns)
Testing: Python 3.11.7
=== ranges.py
Testing: Python 3.12.1
Testing: Python 3.11.7
=== test_decode.py
Testing: Python 3.12.1
/<<PKGBUILDDIR>>/dnslib/digparser.py:144: SyntaxWarning: invalid escape sequence '\d'
  m = re.search('version: (\d+),',edns)
/<<PKGBUILDDIR>>/dnslib/digparser.py:147: SyntaxWarning: invalid escape sequence '\s'
  m = re.search('flags:\s*(.*?);',edns)
/<<PKGBUILDDIR>>/dnslib/digparser.py:150: SyntaxWarning: invalid escape sequence '\d'
  m = re.search('udp: (\d+)',edns)
..................................................................
----------------------------------------------------------------------
Ran 66 tests in 0.134s

Looking at what's new for 3.12, in the 'Other Language Changes' section, this seems to be relevant:

A backslash-character pair that is not a valid escape sequence now generates a [SyntaxWarning](https://docs.python.org/dev/library/exceptions.html#SyntaxWarning), instead of [DeprecationWarning](https://docs.python.org/dev/library/exceptions.html#DeprecationWarning). For example, re.compile("\d+\.\d+") now emits a [SyntaxWarning](https://docs.python.org/dev/library/exceptions.html#SyntaxWarning) ("\d" is an invalid escape sequence, use raw strings for regular expression: re.compile(r"\d+\.\d+")). In a future Python version, [SyntaxError](https://docs.python.org/dev/library/exceptions.html#SyntaxError) will eventually be raised, instead of [SyntaxWarning](https://docs.python.org/dev/library/exceptions.html#SyntaxWarning). (Contributed by Victor Stinner in [gh-98401](https://github.com/python/cpython/issues/98401).)

@nhairs
Copy link

nhairs commented Jan 5, 2024

I'll take a look at this in the work that I'm currently doing over on https://github.com/nhairs/dnslib/tree/typing

@kitterma
Copy link
Author

kitterma commented Jan 5, 2024 via email

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

3 participants