Skip to content

The agent that grows with you

refactor(tools): extract IDENTICAL_STRINGS_ERROR constant

kshitij48db2011b9b9
diff --git a/tests/tools/test_fuzzy_match.py b/tests/tools/test_fuzzy_match.py
index e89afc93656..675126c76c8 100644
--- a/tests/tools/test_fuzzy_match.py
+++ b/tests/tools/test_fuzzy_match.py
@@ -1,6 +1,6 @@
"""Tests for the fuzzy matching module."""
-from tools.fuzzy_match import fuzzy_find_and_replace
+from tools.fuzzy_match import IDENTICAL_STRINGS_ERROR, fuzzy_find_and_replace
class TestExactMatch:
@@ -29,11 +29,7 @@ class TestExactMatch:
new, count, _, err = fuzzy_find_and_replace("abc", "abc", "abc")
assert count == 0
assert new == "abc"
- assert err == (
- "No edit was applied because old_string and new_string are identical. "
- "Provide the existing text to replace in old_string and the changed "
- "replacement text in new_string."
- )
+ assert err == IDENTICAL_STRINGS_ERROR
def test_multiline_exact(self):
content = "line1\nline2\nline3"
@@ -442,12 +438,7 @@ class TestFormatNoMatchHint:
def test_silent_on_identical_strings(self):
"""old_string == new_string — hint irrelevant."""
- result = self.fmt(
- "No edit was applied because old_string and new_string are identical. "
- "Provide the existing text to replace in old_string and the changed "
- "replacement text in new_string.",
- 0, "foo", "foo bar\n",
- )
+ result = self.fmt(IDENTICAL_STRINGS_ERROR, 0, "foo", "foo bar\n")
assert result == ""
def test_silent_when_match_count_nonzero(self):
diff --git a/tools/fuzzy_match.py b/tools/fuzzy_match.py
index 6c142e1253a..360645b4d40 100644
--- a/tools/fuzzy_match.py
+++ b/tools/fuzzy_match.py
@@ -57,6 +57,13 @@ UNICODE_MAP = {
"\u3000": " ", # ideographic (CJK full-width) space
}
+IDENTICAL_STRINGS_ERROR = (
+ "No edit was applied because old_string and new_string are identical. "
+ "Provide the existing text to replace in old_string and the changed "
+ "replacement text in new_string."
+)
+
+
def _unicode_normalize(text: str) -> str:
"""Normalizes Unicode characters to their standard ASCII equivalents."""
for char, repl in UNICODE_MAP.items():
@@ -143,11 +150,7 @@ def fuzzy_find_and_replace(content: str, old_string: str, new_string: str,
return content, 0, None, "old_string is only whitespace — provide non-blank text to match"
if old_string == new_string:
- return content, 0, None, (
- "No edit was applied because old_string and new_string are identical. "
- "Provide the existing text to replace in old_string and the changed "
- "replacement text in new_string."
- )
+ return content, 0, None, IDENTICAL_STRINGS_ERROR
# Try each matching strategy in order
strategies: List[Tuple[str, Callable]] = [