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

Fix SyntaxWarning/DeprecationWarning #158

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

sbrandtb
Copy link
Contributor

This is a DeprecationWarning in Python<3.12 and a SyntaxWarning in Python>=3.12 since \Z is an invalid escape sequence. In every case, this should be made a raw string as also described in the according change note:

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.
 ❯ docker run --rm -it python:3.11-slim python -c "a = ''; a += '/*\Z'; print(a)"
/*\Z

 ❯ docker run --rm -it python:3.11-slim python -c "a = ''; a += r'/*\Z'; print(a)"
/*\Z

 ❯ docker run --rm -it python:3.12-slim python -c "a = ''; a += '/*\Z'; print(a)"
<string>:1: SyntaxWarning: invalid escape sequence '\Z'

/*\Z

 ❯ docker run --rm -it python:3.12-slim python -c "a = ''; a += r'/*\Z'; print(a)"
/*\Z

This is a `DeprecationWarning` in Python<3.12 and a `SyntaxWarning` in
Python>=3.12 since `\Z` is an invalid escape sequence. In every case,
this should be made a raw string as also described in the according
[change note]:

    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.

[change note]: https://docs.python.org/3.12/whatsnew/3.12.html#other-language-changes
@liormizr
Copy link
Owner

Nice one
Thanks for the fix @sbrandtb

@liormizr liormizr merged commit 4d13c4d into liormizr:master Jan 28, 2024
5 checks passed
@sbrandtb
Copy link
Contributor Author

@liormizr could we maybe have a patch release? 🙂

Our pipelines fail on warnings and we are possibly not the only ones having them set up like that

@liormizr
Copy link
Owner

@sbrandtb sure
Version 0.5.2 deployed

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.

2 participants