From bd6f3e574a15520471dae28f44008c513d4998d2 Mon Sep 17 00:00:00 2001 From: Mirochill <200482516+Mirochill@users.noreply.github.com> Date: Thu, 21 May 2026 20:45:33 +0200 Subject: [PATCH] Fix Python 3.14 regex escape warnings --- nbs/00_core.ipynb | 4 ++-- nbs/02_utils.ipynb | 2 +- sql_formatter/core.py | 6 +++--- sql_formatter/utils.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index 359bf4f..6684980 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -1359,7 +1359,7 @@ "def reformat_too_long_line(li, max_len=82):\n", " \"Reformat too long line `li` if it is longer than `max_len` characters after stripping\"\n", " if len(li.strip()) > max_len:\n", - " function_re = re.compile(\"[\\w\\d]+\\(\")\n", + " function_re = re.compile(r\"[\\w\\d]+\\(\")\n", " if function_re.search(li):\n", " out_list = []\n", " in_function = False # indicator for reformatting line with function\n", @@ -3307,7 +3307,7 @@ " if len(split_c) == 1:\n", " split_s[-1] = last_line + \";\"\n", " else:\n", - " split_c[0][\"string\"] = re.sub(\"(.*[\\w\\d]+)(\\s*)$\", r\"\\1;\\2\", split_c[0][\"string\"])\n", + " split_c[0][\"string\"] = re.sub(r\"(.*[\\w\\d]+)(\\s*)$\", r\"\\1;\\2\", split_c[0][\"string\"])\n", " split_s[-1] = \"\".join([d[\"string\"] for d in split_c])\n", " return \"\\n\".join(split_s)" ] diff --git a/nbs/02_utils.ipynb b/nbs/02_utils.ipynb index 9341b2e..e892138 100644 --- a/nbs/02_utils.ipynb +++ b/nbs/02_utils.ipynb @@ -2473,7 +2473,7 @@ " # add comment to it and replace [C] by empty string and [CS] by newline + proper indentation\n", " whitespace = \"\" if match_beginn_cs.match(d[\"comment\"]) else \" \"\n", " fsplit_s_out[line_number] += whitespace + re.sub(\n", - " \"\\[CS\\]\", \n", + " r\"\\[CS\\]\", \n", " \"\\n\" + \" \" * indentation, \n", " replace_c.sub(\"\", d[\"comment\"])\n", " ) \n", diff --git a/sql_formatter/core.py b/sql_formatter/core.py index ab3c3fb..89a8b83 100644 --- a/sql_formatter/core.py +++ b/sql_formatter/core.py @@ -185,7 +185,7 @@ def format_case_when(s): def reformat_too_long_line(li, max_len=82): "Reformat too long line `li` if it is longer than `max_len` characters after stripping" if len(li.strip()) > max_len: - function_re = re.compile("[\w\d]+\(") + function_re = re.compile(r"[\w\d]+\(") if function_re.search(li): out_list = [] in_function = False # indicator for reformatting line with function @@ -440,7 +440,7 @@ def add_semicolon(s): if len(split_c) == 1: split_s[-1] = last_line + ";" else: - split_c[0]["string"] = re.sub("(.*[\w\d]+)(\s*)$", r"\1;\2", split_c[0]["string"]) + split_c[0]["string"] = re.sub(r"(.*[\w\d]+)(\s*)$", r"\1;\2", split_c[0]["string"]) split_s[-1] = "".join([d["string"] for d in split_c]) return "\n".join(split_s) @@ -482,4 +482,4 @@ def format_sql(s, semicolon=False, max_len=82): subquery_pos = extract_outer_subquery(s) # remove whitespace between word and parenthesis s = re.sub(r"\s*\)", ")", s) - return s \ No newline at end of file + return s diff --git a/sql_formatter/utils.py b/sql_formatter/utils.py index a9d3723..28cb48b 100644 --- a/sql_formatter/utils.py +++ b/sql_formatter/utils.py @@ -697,9 +697,9 @@ def assign_comment(fs, cds): # add comment to it and replace [C] by empty string and [CS] by newline + proper indentation whitespace = "" if match_beginn_cs.match(d["comment"]) else " " fsplit_s_out[line_number] += whitespace + re.sub( - "\[CS\]", + r"\[CS\]", "\n" + " " * indentation, replace_c.sub("", d["comment"]) ) s_out = "\n".join(fsplit_s_out) - return s_out \ No newline at end of file + return s_out