Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] gh-106510: Fix DEBUG output for atomic group (GH-106511) #106548

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/re/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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='')
Expand All @@ -136,6 +135,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:
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve debug output for atomic groups in regular expressions.