]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-106510: Fix DEBUG output for atomic group (GH-106511) (GH-106549)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 8 Jul 2023 12:15:22 +0000 (05:15 -0700)
committerGitHub <noreply@github.com>
Sat, 8 Jul 2023 12:15:22 +0000 (15:15 +0300)
(cherry picked from commit 74ec02e9490d8aa086aa9ad9d1d34d2ad999b5af)

Lib/re/_parser.py
Lib/test/test_re.py
Misc/NEWS.d/next/Library/2023-07-07-13-47-28.gh-issue-106510.9n5BdC.rst [new file with mode: 0644]

index f747a0396b1f3bac3a08dfc41a17535473ada649..6b715f54032f916c7dc80866aec9240bf5c80200 100644 (file)
@@ -114,7 +114,6 @@ class SubPattern:
         self.width = None
 
     def dump(self, level=0):
-        nl = True
         seqtypes = (tuple, list)
         for op, av in self.data:
             print(level*"  " + str(op), end='')
@@ -136,6 +135,9 @@ class SubPattern:
                 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:
index 59d0b7b5c48963ea466c6fdffd849234d51bb4e2..167b4400f34c081eb09400afd826e57e9cdf1af1 100644 (file)
@@ -2533,7 +2533,10 @@ ELSE
 
     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 (file)
index 0000000..e0646fa
--- /dev/null
@@ -0,0 +1 @@
+Improve debug output for atomic groups in regular expressions.