[Python-Dev] Emit SyntaxWarning on unrecognized backslash escapes?

Guido van Rossum guido at python.org
Tue Feb 24 19:14:48 CET 2015


On Tue, Feb 24, 2015 at 10:00 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

> On 02/24/2015 09:44 AM, Guido van Rossum wrote:
> >
> > TBH I think this will be a tough sell. I worry that an meme will emerge
> to make all
> > string literals use raw mode, or worse, to deprecate non-raw string
> literals. I'm
> > not sure how we'll get out of the whole conundrum, and I'm not in a
> hurry to see
> > this in 3.5.
>
> So should we move forward with just the better error messages?  It's a
> good first step, and even if it ends up being the
> only step it would be a huge improvement.
>

This is about messages from failing file-open operations if the filename
contains an escaped character? I'd go slow there too: here are a lot of
places where files are opened and messages are printed, both in the C code
and in the stdlib. I'm not sure I buy the argument that just echoing the
repr() of the name back doesn't help -- the escapes in there are actually
useful in case a filename containing garbage chars (or even a trailing
space) was read from some other source.

And I'd weigh the needs of users who know what they are doing somewhat
higher than educating newbies through error messages. While newbies are
most likely to try out open() with a string literal, in "real" programs
that is rare, and filenames are typically taken from the command line or
from some other source where the peculiarities of Python string literals
are irrelevant.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150224/cb8fbf85/attachment.html>


More information about the Python-Dev mailing list