Skip to content

Commit 1c6d6fe

Browse files
refactor: use regex for snake to camel
1 parent 21b6386 commit 1c6d6fe

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

autumn/utils.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import random
23
from typing import Any, Callable, Dict, Set, Type, TypeVar
34

@@ -8,16 +9,10 @@
89
T = TypeVar("T", bound=BaseModel)
910

1011

12+
_CONV_RE = re.compile(r"_([a-z])")
13+
1114
def _snake_to_camel(snake_str: str) -> str:
12-
"""
13-
Convert snake_case string to camelCase string.
14-
"""
15-
components = [c for c in snake_str.split("_") if c]
16-
return (
17-
components[0] + "".join(x.title() for x in components[1:])
18-
if components
19-
else ""
20-
)
15+
return _CONV_RE.sub(lambda match: match.group(1).upper(), snake_str)
2116

2217

2318
def _decompose_value(value: Any) -> Any:

0 commit comments

Comments
 (0)