diff --git a/google/cloud/aiplatform/utils/__init__.py b/google/cloud/aiplatform/utils/__init__.py index 593222ed0a..e726271c90 100644 --- a/google/cloud/aiplatform/utils/__init__.py +++ b/google/cloud/aiplatform/utils/__init__.py @@ -105,6 +105,8 @@ reservation_affinity_v1 as gca_reservation_affinity_v1, ) +_CAMEL_TO_SNAKE_RE = re.compile(r"([A-Z]+)") + VertexAiServiceClient = TypeVar( "VertexAiServiceClient", # v1beta1 @@ -260,7 +262,7 @@ def convert_camel_case_resource_noun_to_snake_case(resource_noun: str) -> str: Returns: Singular snake case resource noun. """ - snake_case = re.sub("([A-Z]+)", r"_\1", resource_noun).lower() + snake_case = _CAMEL_TO_SNAKE_RE.sub(r"_\1", resource_noun).lower() # plural to singular if snake_case in _SINGULAR_RESOURCE_NOUNS or not snake_case.endswith("s"):