[issue28128] Improve the warning message for invalid escape sequences

Eric V. Smith report at bugs.python.org
Mon Oct 31 07:57:36 EDT 2016


Eric V. Smith added the comment:

Serihy:

I had tried this approach earlier, but it doesn't work. With your -5.diff patch, the output is (using Nick's test case):

$ rm -rf __pycache__/ ; ./python -Werror escape_warning.py 
Traceback (most recent call last):
  File "escape_warning.py", line 1, in <module>
    import bad_escape
DeprecationWarning: invalid escape sequence \d
$ 

With my -4.diff patch, you get the desired full stack trace:

$ rm -rf __pycache__/ ; ./python -Wall escape_warning.py 
Traceback (most recent call last):
  File "escape_warning.py", line 1, in <module>
    import bad_escape
  File "/home/eric/local/python/cpython/bad_escape.py", line 1
    print('\d')
         ^
SyntaxError: invalid escape sequence \d
$ 

The trick is: how to make the DeprecationWarning version produce output similar to the SyntaxError case? Note that with DeprecationWarning, you don't see the line in bad_escape.py that actually contains the string with the invalid escape.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28128>
_______________________________________


More information about the Python-bugs-list mailing list