[Python-ideas] Make non-meaningful backslashes illegal in string literals
Andrew Barnert
abarnert at yahoo.com
Sat Aug 8 06:56:20 CEST 2015
On Aug 7, 2015, at 18:52, Ron Adam <ron3200 at gmail.com> wrote:
>
>> On 08/06/2015 12:26 PM, random832 at fastmail.us wrote:
>>> On Wed, Aug 5, 2015, at 14:56, Eric V. Smith wrote:
>>> >Because strings containing \{ are currently valid
>> Which raises the question of why. (and as long as we're talking about
>> things to deprecate in string literals, how about \v?)
>
> (In the below consider x as any character.)
>
> In most languages if \x is not a valid escape character, then an error is raised.
Which most languages? In C, sh, perl, and most of their respective descendants, it means x. (Perl also goes out of its way to guarantee that if x is a punctuation character, it will never mean anything but x in any future version, either in strings or in regexps, so it's always safe to unnecessarily escape punctuation instead of remembering the rules for what punctuation to escape.)
The only language I can think of off the top my head that raises an error is Haskell.
I like the Haskell behavior better than the C/perl behavior, especially given the backward compatibility issues with Python up to 3.5 if it switched, but I don't think it's what most languages do.
More information about the Python-ideas
mailing list