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

gh-128016: Improved invalid escape sequence warning message #128020

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

umarbutler
Copy link

@umarbutler umarbutler commented Dec 17, 2024

This PR improves the warning shown when using an invalid escape sequence by revising it from SyntaxWarning: invalid escape sequence '\W' to "\W" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\W"? A raw string is also an option. as proposed in #128016.

The purpose is to:

  1. Make clear to users that their code will soon break if they continue using backslashes.
  2. Give a simple immediate fix that is guaranteed to work in all cases: add an extra backslash.
  3. Note that raw strings are also an option (and often a good option, though they can sometimes have side effects, cf Hello\n World and\or fizz buzz), as suggested by @hugovk.

At present, speaking from my own experience, the current message does not communicate very clearly the urgent need to cease using invalid escapes lest you create code that will end up broken and also educate on how to quickly fix the issue.

Copy link

cpython-cla-bot bot commented Dec 17, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Dec 17, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Objects/bytesobject.c Outdated Show resolved Hide resolved
Objects/bytesobject.c Outdated Show resolved Hide resolved
Objects/bytesobject.c Outdated Show resolved Hide resolved
Objects/unicodeobject.c Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants