diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-16 10:38:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-16 10:38:26 (GMT) |
commit | 05cb728d68a278d11466f9a6c8258d914135c96c (patch) | |
tree | da7fd67bdacf4239d820bcf40cad9f60cab9fb82 /Lib/sre_parse.py | |
parent | 3daaafb700df45716bb55f3a293f88773baf3463 (diff) | |
download | cpython-05cb728d68a278d11466f9a6c8258d914135c96c.zip cpython-05cb728d68a278d11466f9a6c8258d914135c96c.tar.gz cpython-05cb728d68a278d11466f9a6c8258d914135c96c.tar.bz2 |
bpo-30349: Raise FutureWarning for nested sets and set operations (#1553)
in regular expressions.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r-- | Lib/sre_parse.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 8527412..a53735b 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -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) |