gh-128016: Improved invalid escape sequence warning message (#128020)

This commit is contained in:
Umar Butler 2025-01-16 04:00:54 +11:00 committed by GitHub
parent 40a4d88a14
commit 8d8b854824
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 63 additions and 25 deletions

View file

@ -651,7 +651,9 @@ class CosmeticTestCase(ASTTestCase):
def test_backslash_in_format_spec(self):
import re
msg = re.escape("invalid escape sequence '\\ '")
msg = re.escape('"\\ " is an invalid escape sequence. '
'Such sequences will not work in the future. '
'Did you mean "\\\\ "? A raw string is also an option.')
with self.assertWarnsRegex(SyntaxWarning, msg):
self.check_ast_roundtrip("""f"{x:\\ }" """)
self.check_ast_roundtrip("""f"{x:\\n}" """)