[issue32912] Raise non-silent warning for invalid escape sequences

Serhiy Storchaka report at bugs.python.org
Fri Jun 14 02:20:31 EDT 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

In the particular case of pyparsing there was a bug in the docstring.

     def sub(self, repl): 
         """ 
         Return Regex with an attached parse action to transform the parsed 
         result as if called using `re.sub(expr, repl, string) <https://docs.python.org/3/library/re.html#re.sub>`_. 
  
         Example:: 
  
             make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2</\1>") 
             print(make_html.transformString("h1:main title:")) 
             # prints "<h1>main title</h1>" 
        """

\1 and \2 were interpreted as control characters U+0001 and U+0002, so the user could see 

        make_html = Regex(r"(\w+):(.*?):").sub(r"<^A>^B</^A>")

or

        make_html = Regex(r"(\w+):(.*?):").sub(r"<☺>☻</☺>")

or

        make_html = Regex(r"(\w+):(.*?):").sub(r"<></>")

depending on the output device.

So this examples proves the usefulness of the new warning.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32912>
_______________________________________


More information about the Python-bugs-list mailing list