new to_lower_camel() function (#3473)

* Create utils.py

I needed non pascal case camel case support

* write tests for new `to_lower_camel()` function

* Create 3463-schlerp.md

* added mention to to_lower_camel()

* changed quotes to single tick

* adding second blank line at end of file.

* again, adding second blank line...

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
This commit is contained in:
PattyC
2022-08-05 23:48:19 +09:30
committed by GitHub
parent a26665a5ad
commit d0e5f98be4
4 changed files with 22 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
created new function `to_lower_camel()` for "non pascal case" camel case.
+1 -1
View File
@@ -143,7 +143,7 @@ _(This script is complete, it should run "as is")_
Here camel case refers to ["upper camel case"](https://en.wikipedia.org/wiki/Camel_case) aka pascal case
e.g. `CamelCase`. If you'd like instead to use lower camel case e.g. `camelCase`,
it should be trivial to modify the `to_camel` function above.
instead use the `to_lower_camel` function.
## Alias Precedence
+7
View File
@@ -303,6 +303,13 @@ def to_camel(string: str) -> str:
return ''.join(word.capitalize() for word in string.split('_'))
def to_lower_camel(string: str) -> str:
if len(string) >= 1:
pascal_string = to_camel(string)
return pascal_string[0].lower() + pascal_string[1:]
return string.lower()
T = TypeVar('T')
+13
View File
@@ -37,6 +37,7 @@ from pydantic.utils import (
lenient_issubclass,
path_type,
smart_deepcopy,
to_lower_camel,
truncate,
unique_list,
)
@@ -528,6 +529,18 @@ def test_undefined_pickle():
assert undefined2 is Undefined
def test_on_lower_camel_zero_length():
assert to_lower_camel('') == ''
def test_on_lower_camel_one_length():
assert to_lower_camel('a') == 'a'
def test_on_lower_camel_many_length():
assert to_lower_camel('i_like_turtles') == 'iLikeTurtles'
def test_limited_dict():
d = LimitedDict(10)
d[1] = '1'