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

Use raw strings for regexes in middleware.py #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ProtoxiDe22
Copy link

since python 3.12 this warning will pop up

.venv/lib/python3.12/site-packages/adminrestrict/middleware.py:161: SyntaxWarning: invalid escape sequence '\/'

  for cidr_range in AllowedIP.objects.filter(ip_address__regex="\/\d+$")

this is because backslash escapes are not valid in string literals, see https://docs.python.org/dev/whatsnew/3.12.html#other-language-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.)

the PR uses raw strings for the regexes so this warning is not raised anymore

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 this pull request may close these issues.

1 participant