changeset 50304:805d4a462abb stable

py3: fix for Python 3.12 emitting SyntaxWarning on invalid escape sequences Mercurial became very noisy after https://github.com/python/cpython/commit/a60ddd31be7ff96a8189e7483bf1eb2071d2bddf , for example: $ python3.12 mercurial/store.py mercurial/store.py:406: SyntaxWarning: invalid escape sequence '\.' EXCLUDED = re.compile(b'.*undo\.[^/]+\.(nd?|i)$') This verbosity made some tests fail. The problems were mostly insufficiently escaped regexps, relying on the Python parser/scanner preserving invalid escape sequences.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 07 Mar 2023 16:45:54 +0100
parents 0d3690f8ce2a
children 972f3e5c94b8
files mercurial/match.py tests/test-help.t tests/test-minirst.py tests/testlib/persistent-nodemap-race-ext.py
diffstat 4 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Tue Mar 07 16:25:51 2023 +0100
+++ b/mercurial/match.py	Tue Mar 07 16:45:54 2023 +0100
@@ -196,14 +196,14 @@
     ...     return match(util.localpath(root), *args, **kwargs)
 
     Usually a patternmatcher is returned:
-    >>> _match(b'/foo', b'.', [b're:.*\.c$', b'path:foo/a', b'*.py'])
+    >>> _match(b'/foo', b'.', [br're:.*\.c$', b'path:foo/a', b'*.py'])
     <patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'>
 
     Combining 'patterns' with 'include' (resp. 'exclude') gives an
     intersectionmatcher (resp. a differencematcher):
-    >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], include=[b'path:lib']))
+    >>> type(_match(b'/foo', b'.', [br're:.*\.c$'], include=[b'path:lib']))
     <class 'mercurial.match.intersectionmatcher'>
-    >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build']))
+    >>> type(_match(b'/foo', b'.', [br're:.*\.c$'], exclude=[b'path:build']))
     <class 'mercurial.match.differencematcher'>
 
     Notice that, if 'patterns' is empty, an alwaysmatcher is returned:
@@ -212,7 +212,7 @@
 
     The 'default' argument determines which kind of pattern is assumed if a
     pattern has no prefix:
-    >>> _match(b'/foo', b'.', [b'.*\.c$'], default=b're')
+    >>> _match(b'/foo', b'.', [br'.*\.c$'], default=b're')
     <patternmatcher patterns='.*\\.c$'>
     >>> _match(b'/foo', b'.', [b'main.py'], default=b'relpath')
     <patternmatcher patterns='main\\.py(?:/|$)'>
@@ -223,7 +223,7 @@
     name) matches againset one of the patterns given at initialization. There
     are two ways of doing this check.
 
-    >>> m = _match(b'/foo', b'', [b're:.*\.c$', b'relpath:a'])
+    >>> m = _match(b'/foo', b'', [br're:.*\.c$', b'relpath:a'])
 
     1. Calling the matcher with a file name returns True if any pattern
     matches that file name:
--- a/tests/test-help.t	Tue Mar 07 16:25:51 2023 +0100
+++ b/tests/test-help.t	Tue Mar 07 16:45:54 2023 +0100
@@ -1988,7 +1988,7 @@
 
   $ "$PYTHON" <<EOF
   > def escape(s):
-  >     return b''.join(b'\\u%x' % ord(uc) for uc in s.decode('cp932'))
+  >     return b''.join(br'\\u%x' % ord(uc) for uc in s.decode('cp932'))
   > # translation of "record" in ja_JP.cp932
   > upper = b"\x8bL\x98^"
   > # str.lower()-ed section name should be treated as different one
--- a/tests/test-minirst.py	Tue Mar 07 16:25:51 2023 +0100
+++ b/tests/test-minirst.py	Tue Mar 07 16:45:54 2023 +0100
@@ -154,7 +154,7 @@
 
 debugformats('options', options)
 
-fields = b"""
+fields = br"""
 :a: First item.
 :ab: Second item. Indentation and wrapping
      is handled automatically.
--- a/tests/testlib/persistent-nodemap-race-ext.py	Tue Mar 07 16:25:51 2023 +0100
+++ b/tests/testlib/persistent-nodemap-race-ext.py	Tue Mar 07 16:45:54 2023 +0100
@@ -1,4 +1,4 @@
-"""Create the race condition for issue6554
+r"""Create the race condition for issue6554
 
 The persistent nodemap issues had an issue where a second writer could
 overwrite the data that a previous write just wrote. The would break the append