Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/re/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def addmember(code):
if allow_nested and sourcematch("["):
# A nested set after an operator is the whole operand, used as-is (not
# wrapped in a group); it cannot be combined with loose members.
compound = _parse_charset(source, state, nested + 1)
compound = _parse_charset(source, state, nested + 2)
while True:
this = sourceget()
if this is None:
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,10 @@ def test_set_operations(self):
with warnings.catch_warnings():
warnings.simplefilter('error', FutureWarning)
re.compile(r'[a-z--[aeiou]]')
# A reserved construct inside a nested operand warns against the caller.
with self.assertWarnsRegex(FutureWarning, 'Possible nested set ') as w:
re.compile(r'[a--[[b]]]')
self.assertEqual(w.filename, __file__)

# Set union A||B == A or B (an explicit form of [AB]); flat operands
# merge into one charset, otherwise the operations are alternated.
Expand All @@ -1557,6 +1561,10 @@ def test_set_operations(self):
self.assertEqual(re.findall(r'[\d~~1]', s), list('0123456789~'))
self.assertEqual(w.filename, __file__)
self.assertEqual(re.findall(r'[~~1]', s), list('1~'))
with self.assertWarnsRegex(FutureWarning,
'Possible set symmetric difference ') as w:
re.compile(r'[a||[c~~d]]')
self.assertEqual(w.filename, __file__)

def test_search_coverage(self):
self.assertEqual(re.search(r"\s(b)", " b").group(1), "b")
Expand Down
Loading