diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-03-19 14:09:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-19 14:09:45 (GMT) |
commit | 906f1a4a95e9ca82171a40a28b16533a14fa339c (patch) | |
tree | fccdb6d24098bd35d9c39419af0b803a7741fe8b /Lib/sre_parse.py | |
parent | c1f327f30db09388fc777196e233b7a6182c6efa (diff) | |
download | cpython-906f1a4a95e9ca82171a40a28b16533a14fa339c.zip cpython-906f1a4a95e9ca82171a40a28b16533a14fa339c.tar.gz cpython-906f1a4a95e9ca82171a40a28b16533a14fa339c.tar.bz2 |
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 4142961b9f5ad3bf93976a6a7162f8049e354018)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r-- | Lib/sre_parse.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 8311916..5370667 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -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 ) |