[Python-ideas] Make undefined escape sequences have SyntaxWarnings

MRAB python at mrabarnett.plus.com
Wed Oct 10 22:11:49 CEST 2012


On 2012-10-10 20:46, Antoine Pitrou wrote:
> On Wed, 10 Oct 2012 15:36:08 -0400
> Mike Graham <mikegraham at gmail.com> wrote:
>> The literal"\c" should be an error but in practice means "\\c". It's
>> probably too late to make this invalid syntax as it out to be, but I
>> wonder if a warning isn't in order, especially with the theoretical
>> potential of adding new string escapes in the future.
>
> -1. This will make life more difficult with regular expressions (and
> produce lots of spurious warnings in existing code).
>
How would it make life more difficult with regular expressions?

I would've preferred:

1. Unknown escapes in string literals give a compile-time error

2. Raw string literals treat backslashes as pure literals

3. Unknown escapes in regex patterns give a run-time error

Unfortunately, changing them would break existing code. (I retain the
behaviour of re in the regex module for this reason, not that I like
it. :-()

It would've been nice if the 'fix' had been made in Python 3...



More information about the Python-ideas mailing list