paulc / dnslib

A Python library to encode/decode DNS wire-format packets
https://github.com/paulc/dnslib
BSD 2-Clause "Simplified" License
295 stars 84 forks source link

SyntaxWarning with Python 3.12 #60

Open kitterma opened 6 months ago

kitterma commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

Great. Thanks,

Scott K