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

Nick Coghlan ncoghlan at gmail.com
Mon Feb 23 23:40:01 CET 2015


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

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list