-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Make SyntaxWarning
for invalid escape sequences better reflect their intended deprecation
#128016
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
Comments
@umarbutler, are you comfortable creating a PR for this? |
@ethanfurman Yes, I'm going to have a crack at it. I'm not a C programmer but the change doesn't seem too difficult. |
Just an update, I have revised the proposed wording to |
We can remove "Such sequences":
Let's also mention raw strings, as in many cases raw strings are a cleaner and easier solution. In the thread you say:
This is a suggestion, it doesn't have to cover all the edge cases. We can add more detail to the docs. |
@hugovk The reason I included 'Such sequences' is that this warning could raise for It's a bit pedantic but the current construction avoids ingraining into developers that With all that said, if you still feel that its better to run with
Hmm... We could do That way the user gets an immediate suggested fix guaranteed to work (in line with the broader reasoning of why |
This tends to look more and more verbose. More intended to regular docs, not to the error message, that should (IMO) just explain what's goes wrong.
Why the Python docs are wrong place to such things? I would expect, that current deprecations are listed in the whatsnew. Bad news, to read about the given deprecation you should navigate to past release notes. I would expect to see this somewhere in latest Pending Removal* sections. But no. Perhaps it's a documentation issue. |
@skirpichev Please see the discussions here and here. I understand that it might seem obvious to you but to me, on its own, the message A couple extra characters added to a warning message that should ideally not affect anyone familar with the problem anyways (as they would hopefully understand that they now need to use raw strings and/or escaped backslashes) will provide new and/or unexperienced users far more value than the harm of making it a little more verbose, in my view at least. Not everyone reads the Whats New. And new users shouldn't really be expected to have to do that to understand this warning. It really should speak for itself. |
How about this wording:
Changes:
Yes, it's longer, but I think this kind of error text is an important "Explicit is better than implicit" case. (And for experienced users who did just make a typo, the important part is still front-loaded.) |
@zahlman I think the current wording already adequately captures the two key pieces of information it needs to capture:
Those are the two key pieces of information that need to be conveyed. Your proposed wording is a bit too long and may overload the user with information and take longer for them to get the core message. 'invalid escape sequences' is the term currently used by existing Python documentation so it's probably best to avoid changing it. It is also used by other programming languages and so has its own meaning. I think a lot of the information you've proposed adding is information that users can easily find online on Stack Overflow or Python documentation. The purpose of the revised wording is really to give them a quick fix and a little heads up that their code will break. Also the wording of 'Did you mean?' is already used in the IMO the current wording is sufficently concise and clear. |
Fixed by the change 8d8b854. I close the issue. |
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
I would like to propose that the
SyntaxWarning
that is raised when an invalid escape sequence is used be updated to better reflect the fact that the ability of Python users to employ invalid escape sequences is intended to be removed in a future Python release.At present, if one runs the code
path = 'C:\Windows'
in Python, they get this warning:SyntaxWarning: invalid escape sequence '\W'
.I argue that that warning is not as semantically meaningful as it could be. It does not immediately convey to the untrained and/or uninitiated that
path = 'C:\Windows'
will in fact break in a future Python release.What is a better of way communicating that? How about,
SyntaxWarning: '\W' is currently an invalid escape sequence. In the future, invalid escape sequences will raise a SyntaxError. Did you mean '\\W'?
.That message is a little bit longer but it immediately tells the user, without the need for heading to Stack Overflow or Python documentation, that:
Whereas all that
SyntaxWarning: invalid escape sequence '\W'
tells me is, at best, hey, there's something wrong here, but you've gotta figure out what that is. Someone could easily read that message and think maybe Python is trying to be helpful and make me double check that I didn't actually mean to type a valid escape sequence like\f
or\n
.A message like
SyntaxWarning: '\W' is currently an invalid escape sequence. In the future, invalid escape sequences will raise a SyntaxError. Did you mean '\\W'?
makes it much more difficult to come away with the message that the Python developers might not like what I've just done but it works and it'll keep working forever.Update: The proposed message has been revised to
"\W" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\W"?
following consultation.Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/make-syntaxwarning-for-invalid-escape-sequences-better-reflect-their-intended-deprecation/74416/2
Linked PRs
The text was updated successfully, but these errors were encountered: