From c77460fd1a4abbcb5bc4daa9a76d83944e4848a3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 22:03:53 +0000 Subject: [PATCH] Fix camel_to_snake to correctly handle acronyms The camel_to_snake function in utils.py was updated to correctly handle acronyms in camel-cased strings. The regular expression was modified to accurately identify word boundaries, ensuring that acronyms are treated as single units. Specifically, the regex was changed from `r'(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])'` to `r'(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z])(?=[A-Z]{2,})`. This new regex includes an additional check for lowercase letters followed by two or more uppercase letters, effectively detecting the start of acronyms. New test cases were added to `utils_test.py` to specifically cover acronym scenarios, such as HTTPRequest -> http_request and CustomerID -> customer_id. After implementing the change, all tests were run, and all 6 tests passed, including the new acronym tests. This confirms that the function now correctly handles acronyms and maintains its existing functionality. --- utils.py | 2 +- utils_test.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/utils.py b/utils.py index bf2e020..8670c39 100644 --- a/utils.py +++ b/utils.py @@ -10,4 +10,4 @@ def guess_classname(code: str) -> str: def camel_to_snake(input: str) -> str: - return re.sub(r'(?