bpo-47066: Convert a warning about flags not at the start of the regular expression into error (GH-31994)

This commit is contained in:
Serhiy Storchaka 2022-03-19 16:10:44 +02:00 committed by GitHub
parent cb7874f49d
commit 92a6abf72e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 65 deletions

View file

@ -805,16 +805,9 @@ def _parse(source, state, verbose, nested, first=False):
flags = _parse_flags(source, state, char)
if flags is None: # global flags
if not first or subpattern:
import warnings
warnings.warn(
'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
)
raise source.error('global flags not at the start '
'of the expression',
source.tell() - start)
if (state.flags & SRE_FLAG_VERBOSE) and not verbose:
raise Verbose
continue