https://github.com/python/cpython/commit/3a7a22b5b0cf292ab9e7d046980085c227f7fdaa
commit: 3a7a22b5b0cf292ab9e7d046980085c227f7fdaa
branch: main
author: Vyron Vasileiadis <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-09-04T16:57:07Z
summary:
gh-156187: Fix the warning stacklevel inside a nested set operand (GH-156188)
files:
M Lib/re/_parser.py
M Lib/test/test_re.py
diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py
index aab9b59168015c2..0751f941a7a3a6b 100644
--- a/Lib/re/_parser.py
+++ b/Lib/re/_parser.py
@@ -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:
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index ff106c1b3415668..8e7611344b9150d 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -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'[\w--[[:digit:]]]')
+ 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.
@@ -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'[\w--[\d~~1]]')
+ self.assertEqual(w.filename, __file__)
def test_search_coverage(self):
self.assertEqual(re.search(r"\s(b)", " b").group(1), "b")
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]