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

MRAB python at mrabarnett.plus.com
Tue Feb 24 00:40:55 CET 2015


On 2015-02-23 22:50, Nick Coghlan wrote:
> On 24 February 2015 at 08:40, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> On 24 February 2015 at 07:39, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>>> On 23/02/2015 21:27, Serhiy Storchaka wrote:
>>>>
>>>> On 23.02.15 21:58, Joao S. O. Bueno wrote:
>>>>>
>>>>> That happens all the time, and is this use case that should possibly
>>>>> be addressed here - maybe
>>>>> something as simple as adding a couple of paragraphs to different places
>>>>> in the documentation could mitigate the issue. (in contrast to make a
>>>>> tons of otherwise valid code
>>>>> to become deprecated in a couple releases).
>>>>
>>>>
>>>> The problem is that the user don't know that he should read the
>>>> documentation. It just find that his script works with "C:\sample.txt",
>>>> but doesn't work with "D:\test.txt". He has no ideas what happen.
>>>
>>> Isn't this why users have help desks?
>>
>> Most don't, and cases like "\n" or "\t" in a Windows path name being
>> converted to whitespace are utterly impossible to look up in an
>> internet search when they fail, so a user learning on their own gets
>> left with a broken program and no particularly effective ways to ask
>> for help figuring it out.
>>
>> Like Unicode encoding errors they may appear a long way from the
>> source of the offending data value (in this case, likely to be a file
>> name copy and pasted from elsewhere on their system), and they don't
>> give a particularly helpful error message (especially when the escape
>> sequences are for whitespace).
>>
>> While I originally disliked the idea, I think this is a genuine
>> usability issue on Windows that would be worth addressing. However,
>> it's a significant enough change that I believe it needs a PEP and a
>> reasonably long transition period before anything actually breaks. For
>> example:
>>
>> - pep8 and pylint warnings as soon as a patch can be accepted
>> - Py3kWarning in Python 2.7.x
>> - DeprecationWarning in Python 3.5
>> - SyntaxWarning in Python 3.6
>> - SyntaxError in Python 3.7
>
> Another suggestion: we may want to turn this particular deprecation
> warning on by default in the interactive interpreter, and recommend
> that other interactive interpreter developers (such as the IPython
> folks) consider doing the same.
>
While we're at it, could something similar also be done to re? In that
instance, unknown escapes with ASCII-range letters _drop_ the backslash:

 >>> re.match(r'\q', 'q')
<_sre.SRE_Match object; span=(0, 1), match='q'>



More information about the Python-Dev mailing list