Skip to content

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

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

Merged
merged 11 commits into from
Jan 15, 2025

Conversation

umarbutler
Copy link
Contributor

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

@ghost
Copy link

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

@umarbutler
Copy link
Contributor Author

@vstinner How long does it usually take for a PR like this to get merged?

@pablogsal @lysnikolaou

@vstinner
Copy link
Member

@vstinner How long does it usually take for a PR like this to get merged?

There is no rule. It depends.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@vstinner vstinner merged commit 8d8b854 into python:main Jan 15, 2025
45 checks passed
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.

4 participants