Skip to content

Commit f9bc2e9

Browse files
author
ebembi-crdb
committed
Fix f-string backslash syntax error for Python < 3.12
version.replace('.', '\.') inside an f-string {} is a SyntaxError on Python < 3.12. Pre-compute the escaped version into a local variable before using it in the f-string expression.
1 parent 4f5fc9c commit f9bc2e9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/current/create_all_archives_fixed.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ def fix_navigation_in_archive(version):
6161
r"/\\/\(\[\^/\]\+\)\\/\(docs\|v[\d\.\\]+\|releases\|advisories\|cockroachcloud\|molt\)\\//\);",
6262
)
6363
if old_archive_match.search(txt):
64+
# Pre-compute escaped version outside the f-string to stay
65+
# compatible with Python < 3.12 (no backslashes inside {}).
66+
ver_escaped = version.replace(".", "\\.")
6467
txt = old_archive_match.sub(
6568
f"var archiveMatch = currentPath.match("
66-
f"/\\/([^\\/]+)\\/(docs|{version.replace('.', '\\.')}|releases|advisories|cockroachcloud|molt)\\//);",
69+
f"/\\/([^\\/]+)\\/(docs|{ver_escaped}|releases|advisories|cockroachcloud|molt)\\//);",
6770
txt,
6871
)
6972

0 commit comments

Comments
 (0)