[Python-checkins] gh-106510: Fix DEBUG output for atomic group (GH-106511)
serhiy-storchaka
webhook-mailer at python.org
Sat Jul 8 07:31:28 EDT 2023
https://github.com/python/cpython/commit/74ec02e9490d8aa086aa9ad9d1d34d2ad999b5af
commit: 74ec02e9490d8aa086aa9ad9d1d34d2ad999b5af
branch: main
author: Serhiy Storchaka <storchaka at gmail.com>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2023-07-08T14:31:25+03:00
summary:
gh-106510: Fix DEBUG output for atomic group (GH-106511)
files:
A Misc/NEWS.d/next/Library/2023-07-07-13-47-28.gh-issue-106510.9n5BdC.rst
M Lib/re/_parser.py
M Lib/test/test_re.py
diff --git a/Lib/re/_parser.py b/Lib/re/_parser.py
index 6c8a4eccc0e0b..22d10ab6e31d3 100644
--- a/Lib/re/_parser.py
+++ b/Lib/re/_parser.py
@@ -113,7 +113,6 @@ def __init__(self, state, data=None):
self.width = None
def dump(self, level=0):
- nl = True
seqtypes = (tuple, list)
for op, av in self.data:
print(level*" " + str(op), end='')
@@ -135,6 +134,9 @@ def dump(self, level=0):
if item_no:
print(level*" " + "ELSE")
item_no.dump(level+1)
+ elif isinstance(av, SubPattern):
+ print()
+ av.dump(level+1)
elif isinstance(av, seqtypes):
nl = False
for a in av:
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 8f26d0aacf4ee..b1699b0f83dbd 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -2489,7 +2489,10 @@ def test_debug_flag(self):
def test_atomic_group(self):
self.assertEqual(get_debug_out(r'(?>ab?)'), '''\
-ATOMIC_GROUP [(LITERAL, 97), (MAX_REPEAT, (0, 1, [(LITERAL, 98)]))]
+ATOMIC_GROUP
+ LITERAL 97
+ MAX_REPEAT 0 1
+ LITERAL 98
0. INFO 4 0b0 1 2 (to 5)
5: ATOMIC_GROUP 11 (to 17)
diff --git a/Misc/NEWS.d/next/Library/2023-07-07-13-47-28.gh-issue-106510.9n5BdC.rst b/Misc/NEWS.d/next/Library/2023-07-07-13-47-28.gh-issue-106510.9n5BdC.rst
new file mode 100644
index 0000000000000..e0646fa9bc021
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-07-13-47-28.gh-issue-106510.9n5BdC.rst
@@ -0,0 +1 @@
+Improve debug output for atomic groups in regular expressions.
More information about the Python-checkins
mailing list