Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: resolve SyntaxWarning from invalid escape sequences #2

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

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

Conversation

carlstoker
Copy link

With Python 3.12, the following change was made:

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

This causes warnings, which will become errors in future versions, such as

chap02/calc/calc_lexer.py:43: SyntaxWarning: invalid escape sequence '\e'
tokens.append(Token('EOF', '\eof'))

Replacing '\eof' with r'\eof' is sufficient to resolve this.

I diff'ed the output of python3.11 running the upstream code vs python 3.12 running the modified code using these commands:

diff <(python3.11 upstream/chap02/calc/calc_lexer.py) <(python3.12 plipy-code/chap02/calc/calc_lexer.py)

There were no differences between the two.

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