mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-30349: Raise FutureWarning for nested sets and set operations (#1553)
in regular expressions.
This commit is contained in:
parent
3daaafb700
commit
05cb728d68
8 changed files with 106 additions and 9 deletions
|
@ -517,6 +517,12 @@ def _parse(source, state, verbose, nested, first=False):
|
|||
setappend = set.append
|
||||
## if sourcematch(":"):
|
||||
## pass # handle character classes
|
||||
if source.next == '[':
|
||||
import warnings
|
||||
warnings.warn(
|
||||
'Possible nested set at position %d' % source.tell(),
|
||||
FutureWarning, stacklevel=nested + 6
|
||||
)
|
||||
negate = sourcematch("^")
|
||||
# check remaining characters
|
||||
while True:
|
||||
|
@ -529,6 +535,17 @@ def _parse(source, state, verbose, nested, first=False):
|
|||
elif this[0] == "\\":
|
||||
code1 = _class_escape(source, this)
|
||||
else:
|
||||
if set and this in '-&~|' and source.next == this:
|
||||
import warnings
|
||||
warnings.warn(
|
||||
'Possible set %s at position %d' % (
|
||||
'difference' if this == '-' else
|
||||
'intersection' if this == '&' else
|
||||
'symmetric difference' if this == '~' else
|
||||
'union',
|
||||
source.tell() - 1),
|
||||
FutureWarning, stacklevel=nested + 6
|
||||
)
|
||||
code1 = LITERAL, _ord(this)
|
||||
if sourcematch("-"):
|
||||
# potential range
|
||||
|
@ -545,6 +562,13 @@ def _parse(source, state, verbose, nested, first=False):
|
|||
if that[0] == "\\":
|
||||
code2 = _class_escape(source, that)
|
||||
else:
|
||||
if that == '-':
|
||||
import warnings
|
||||
warnings.warn(
|
||||
'Possible set difference at position %d' % (
|
||||
source.tell() - 2),
|
||||
FutureWarning, stacklevel=nested + 6
|
||||
)
|
||||
code2 = LITERAL, _ord(that)
|
||||
if code1[0] != LITERAL or code2[0] != LITERAL:
|
||||
msg = "bad character range %s-%s" % (this, that)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue