From 8ae3045154a8ca25c80558f3d86d490b3fe4d9f5 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Wed, 11 Jun 2025 19:48:36 -0700 Subject: [PATCH] Silence Python warnings about invalid backslashes. This patch fixes the following warnings: /home/collin/.local/src/redis-docs/build/components/component.py:464: SyntaxWarning: invalid escape sequence '\.' f'find {self._content} -regex ".*\.md"').strip().split('\n') /home/collin/.local/src/redis-docs/build/components/markdown.py:250: SyntaxWarning: invalid escape sequence '\[' self.payload = re.sub(f'(\[.+?\])(\(.+?\))', rep, self.payload) /home/collin/.local/src/redis-docs/build/components/example.py:17: SyntaxWarning: invalid escape sequence '\[' 'c#': '\[Fact\]|\[SkipIfRedis\(.*\)\]' The first one should be marked raw since we want the '\' to be passed to the shell. The others are not needed. Using "\]" is only required when trying to match the literal ']' in a set of characers. --- build/components/component.py | 2 +- build/components/example.py | 2 +- build/components/markdown.py | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/build/components/component.py b/build/components/component.py index ba6a6e73da..7da3d18a04 100644 --- a/build/components/component.py +++ b/build/components/component.py @@ -461,7 +461,7 @@ def _process_module_docs(self, files: list) -> None: md.persist() files = run( - f'find {self._content} -regex ".*\.md"').strip().split('\n') + fr'find {self._content} -regex ".*\.md"').strip().split('\n') for f in files: md = Markdown(f) t = md.fm_data.pop('type', None) diff --git a/build/components/example.py b/build/components/example.py index 855776dd1a..955c9187d3 100644 --- a/build/components/example.py +++ b/build/components/example.py @@ -14,7 +14,7 @@ 'java-sync': '@Test', 'java-async': '@Test', 'java-reactive': '@Test', - 'c#': '\[Fact\]|\[SkipIfRedis\(.*\)\]' + 'c#': r'\[Fact]|\[SkipIfRedis\(.*\)]' } PREFIXES = { 'python': '#', diff --git a/build/components/markdown.py b/build/components/markdown.py index c21178d7e4..9d7536500c 100644 --- a/build/components/markdown.py +++ b/build/components/markdown.py @@ -77,9 +77,8 @@ def add_github_metadata(self, github_repo: str, github_branch: str, github_path: self.fm_data['github_path'] = github_path def report_links(self) -> None: - links = re.findall(r'(\[.+\])(\(.+\))', self.payload) exc = ['./', '#', '/commands', '/community', '/docs', '/topics'] - for link in links: + for link in re.finditer(r'(\[.+])(\(.+\))', self.payload): ex = False for e in exc: if link[1].startswith(f'({e}'): @@ -247,4 +246,4 @@ def rep(x): return r else: return x.group(0) - self.payload = re.sub(f'(\[.+?\])(\(.+?\))', rep, self.payload) + self.payload = re.sub(r'(\[.+])(\(.+\))', rep, self.payload)