Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MakeSyntaxWarning for invalid escape sequences better reflect their intended deprecation #128016

Closed
Labels
@umarbutler

Description

@umarbutler

Feature or enhancement

Proposal:

I would like to propose that theSyntaxWarning 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 isintended to be removed in a future Python release.

At present, if one runs the codepath = '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 theuntrained and/oruninitiated thatpath = 'C:\Windows' will in factbreak 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 longerbut it immediately tells the user, without the need for heading to Stack Overflow or Python documentation, that:

  1. Although the code runs today,it won't run soon!
  2. You can fix the code easily,just add an extra backslash.

Whereas all thatSyntaxWarning: 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 likeSyntaxWarning: '\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"? followingconsultation.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp