bpo-32912: Upgrade warning for invalid escape sequences from silent to non-silent by Vgr255 · Pull Request #5849 · python/cpython
| NULL, NULL) < 0) | ||
| { | ||
| if (PyErr_ExceptionMatches(PyExc_DeprecationWarning)) { | ||
| if (PyErr_ExceptionMatches(PyExc_SyntaxWarning)) { |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the comment below.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the end goal here is to get a SyntaxError, however this is not yet possible as we have to wait for two releases before this can happen, so we can't yet convert it to a SyntaxError. I probably should update that comment, though (I'll do that tomorrow when I get home).
| return NULL; | ||
| if (first_invalid_escape != NULL) { | ||
| if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, | ||
| if (PyErr_WarnFormat(PyExc_SyntaxWarning, 1, |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to syntax.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning was added back in 3.6 when we started deprecating the invalid escapes. In 3.8, we're upgrading these to SyntaxWarning so that they're no longer silent by default, and it will eventually be a SyntaxError. The end goal here is to raise a SyntaxError for this use, but this will have to wait for two more releases.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning is emitted by the "unicode-escape" codec.
>>> b'\\z'.decode('unicode-escape')
__main__:1: DeprecationWarning: invalid escape sequence '\z'
'\\z'
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and this warning was added as part of bpo-27364 to keep consistency with the rest of the language. It only makes sense to upgrade this warning along with everything else, or else this codec falls out of sync with the rest of the language.
| return NULL; | ||
| if (first_invalid_escape != NULL) { | ||
| if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, | ||
| if (PyErr_WarnFormat(PyExc_SyntaxWarning, 1, |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to syntax.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning was added back in 3.6 when we started deprecating the invalid escapes. In 3.8, we're upgrading these to SyntaxWarning so that they're no longer silent by default, and it will eventually be a SyntaxError. The end goal here is to raise a SyntaxError for this use, but this will have to wait for two more releases.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this warning is emitted by codecs.escape_decode() (which is used in pickle).
>>> codecs.escape_decode(b'\\z')
__main__:1: DeprecationWarning: invalid escape sequence '\z'
(b'\\z', 2)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and this warning was added as part of bpo-27364 to keep consistency with the rest of the language. It only makes sense to upgrade this warning along with everything else, or else the codecs module falls out of sync with the rest of the language.