[issue31136] raw strings cannot end with a backslash character r'\'

Graham Wideman report at bugs.python.org
Wed Feb 20 21:23:45 EST 2019


Graham Wideman <initcontact at grahamwideman.com> added the comment:

Let us be clear here that this is NOT a case where the backslash escapes the subsequent quote. If it WAS such a case, then the sequence \' would leave only the quote in the output string. But it doesn't; it leaves the complete 2-character \' in the output string.
So essentially this is a case of the character sequence \' being given a special status that causes that character pair to have a special meaning in preference to the meaning of the individual characters.
So this IS a bug -- it may be "as designed", but that produces the bug in the name of this feature, "raw string", which is patently misleading and in violation of the principle of least surprise. This is a feature (as the FAQ explains) provided explicitly for developers of regular expression parsers. So at best, these r-strings should be called "regex-oriented" string literals, which can be used elsewhere, at risk of knowing this gotcha.

----------
nosy: +gwideman

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


More information about the Python-bugs-list mailing list