File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 2020
2121
2222def to_snake_case (name : str ) -> str :
23- """Converts a PascalCase name to snake_case."""
24- return re .sub (r"(?<!^)(?=[A-Z])" , "_" , name ).lower ()
23+ """Converts a PascalCase name to snake_case, handling acronyms."""
24+ if not name :
25+ return ""
26+ # Add underscore between lower and upper case
27+ name = re .sub (r"([a-z0-9])([A-Z])" , r"\1_\2" , name )
28+ # Add underscore between multiple upper case and a following lower case
29+ name = re .sub (r"([A-Z])([A-Z][a-z])" , r"\1_\2" , name )
30+ return name .lower ()
2531
2632
2733def generate_service_names (class_name : str ) -> Dict [str , str ]:
@@ -60,12 +66,18 @@ def method_to_request_class_name(method_name: str) -> str:
6066 Returns:
6167 The inferred PascalCase name for the corresponding request class.
6268
69+ Raises:
70+ ValueError: If method_name is empty.
71+
6372 Example:
6473 >>> method_to_request_class_name('get_dataset')
6574 'GetDatasetRequest'
6675 >>> method_to_request_class_name('list_jobs')
6776 'ListJobsRequest'
6877 """
78+ if not method_name :
79+ raise ValueError ("method_name cannot be empty" )
80+
6981 # e.g., "get_dataset" -> ["get", "dataset"]
7082 parts = method_name .split ("_" )
7183 # e.g., ["get", "dataset"] -> "GetDataset"
You can’t perform that action at this time.
0 commit comments