[PATCH 3 of 5] python3.13: address deprecation of re.sub positional argument 'count'

Mads Kiilerich mads at kiilerich.com
Thu Jan 11 23:59:54 UTC 2024


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1705006735 -3600
#      Thu Jan 11 21:58:55 2024 +0100
# Branch stable
# Node ID 8e16bc622b04e2eabb3a47138aa3bdffba03e142
# Parent  a06a7677696d8fa4fc3e33923425ef3fadd6f441
python3.13: address deprecation of re.sub positional argument 'count'

Python 3.13 introduced:

  DeprecationWarning: 'count' is passed as positional argument

Making it mandatory to pass 'count' as named argument reduces the risk of
passing 'flags' to it. That is exactly what happened in test-doctest.py .

diff --git a/mercurial/subrepoutil.py b/mercurial/subrepoutil.py
--- a/mercurial/subrepoutil.py
+++ b/mercurial/subrepoutil.py
@@ -112,7 +112,7 @@ def state(ctx, ui):
             # extra escapes are needed because re.sub string decodes.
             repl = re.sub(br'\\\\([0-9]+)', br'\\\1', repl)
             try:
-                src = re.sub(pattern, repl, src, 1)
+                src = re.sub(pattern, repl, src, count=1)
             except re.error as e:
                 raise error.Abort(
                     _(b"bad subrepository pattern in %s: %s")
diff --git a/tests/test-doctest.py b/tests/test-doctest.py
--- a/tests/test-doctest.py
+++ b/tests/test-doctest.py
@@ -21,9 +21,9 @@ class py3docchecker(doctest.OutputChecke
             r'''^mercurial\.\w+\.(\w+): (['"])(.*?)\2''',
             r'\1: \3',
             got2,
-            re.MULTILINE,
+            flags=re.MULTILINE,
         )
-        got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, re.MULTILINE)
+        got2 = re.sub(r'^mercurial\.\w+\.(\w+): ', r'\1: ', got2, flags=re.MULTILINE)
         return any(
             doctest.OutputChecker.check_output(self, w, g, optionflags)
             for w, g in [(want, got), (want2, got2)]



More information about the Mercurial-devel mailing list