From 7452a68d2d67aeccb19bbff926b0d2e7cb93b5e2 Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Tue, 10 Dec 2024 14:53:46 +0800 Subject: [PATCH] fix Python3.12 reg ex warnings I'm getting the following warnings with Python3.12: /home/mjk/git/slothy/slothy/helper.py:778: SyntaxWarning: invalid escape sequence '\(' l = re.sub(f"\\\\{arg}\\\\\(\)", val, l) /home/mjk/git/slothy/slothy/helper.py:819: SyntaxWarning: invalid escape sequence '\s' macro_regexp_txt += '(,|\s)'.join(arg_regexps) This commit fixes the escaping. --- slothy/helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slothy/helper.py b/slothy/helper.py index 51b0eb66..ddc53e4f 100644 --- a/slothy/helper.py +++ b/slothy/helper.py @@ -775,7 +775,7 @@ def prepare_value(a): return a def apply_arg(l, arg, val): - l = re.sub(f"\\\\{arg}\\\\\(\)", val, l) + l = re.sub(f"\\\\{arg}\\\\\\(\\)", val, l) l = re.sub(f"\\\\{arg}(\\W|$)",val + "\\1", l) l = l.replace("\\()\\()", "\\()") return l @@ -816,7 +816,7 @@ def unfold_in(self, source, change_callback=None, inherit_comments=False): for arg in self.args: arg_regexps.append(rf"\s*(?P<{arg}>[^,]+)\s*") - macro_regexp_txt += '(,|\s)'.join(arg_regexps) + macro_regexp_txt += '(,|\\s)'.join(arg_regexps) macro_regexp = re.compile(macro_regexp_txt) output = []