vishalanandl177 / DRF-API-Logger

An API Logger for your Django Rest Framework project.
https://github.com/vishalanandl177/DRF-API-Logger
Apache License 2.0
303 stars 57 forks source link

SyntaxWarning on line 63 of utils.py in Python 3.12 #94

Closed gwachob closed 5 months ago

gwachob commented 5 months ago

Seeing an warning on our django deployment:

drf_api_logger/utils.py:63: SyntaxWarning: invalid escape sequence '\g

I believe the string that includes the \g escape just needs to be an r-string (e.g. r'\g<1>***FILTERED***\g<3>') to remove this warning.

I believe this is due to a new Python 3.12 feature - second bullet point of https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes - which also indicates this will become a SyntaxError in the future:

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.)

vishalanandl177 commented 5 months ago

The issue is now fixed, it will be part of the next release.