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:45 -07:00 committed by GitHub
parent c1f327f30d
commit 906f1a4a95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -807,9 +807,11 @@ def _parse(source, state, verbose, nested, first=False):
if not first or subpattern:
import warnings
warnings.warn(
'Flags not at the start of the expression %r%s' % (
'Flags not at the start of the expression %r%s'
' but at position %d' % (
source.string[:20], # truncate long regexes
' (truncated)' if len(source.string) > 20 else '',
start,
),
DeprecationWarning, stacklevel=nested + 6
)