bpo-39394: Improve warning message in the re module (GH-31988)

A warning about inline flags not at the start of the regular
expression now contains the position of the flag.
(cherry picked from commit 4142961b9f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-03-19 07:09:59 -07:00 committed by GitHub
parent fcd5799689
commit cbcd2e36d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -1443,7 +1443,8 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
str(warns.warnings[0].message),
'Flags not at the start of the expression %r' % p
'Flags not at the start of the expression %r'
' but at position 1' % p
)
self.assertEqual(warns.warnings[0].filename, __file__)
@ -1452,7 +1453,8 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match(p, lower_char))
self.assertEqual(
str(warns.warnings[0].message),
'Flags not at the start of the expression %r (truncated)' % p[:20]
'Flags not at the start of the expression %r (truncated)'
' but at position 1' % p[:20]
)
self.assertEqual(warns.warnings[0].filename, __file__)
@ -1464,7 +1466,8 @@ class ReTests(unittest.TestCase):
self.assertTrue(re.match(p, b'a'))
self.assertEqual(
str(warns.warnings[0].message),
'Flags not at the start of the expression %r' % p
'Flags not at the start of the expression %r'
' but at position 1' % p
)
self.assertEqual(warns.warnings[0].filename, __file__)