Skip to content

Commit

Permalink
Capitalize literal names
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Apr 24, 2024
1 parent d0214f2 commit 635aed6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mypy_boto3_builder/parsers/shape_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
WaiterConfigTypeDef,
)
from mypy_boto3_builder.utils.boto3_utils import get_botocore_session
from mypy_boto3_builder.utils.strings import get_type_def_name
from mypy_boto3_builder.utils.strings import capitalize, get_type_def_name


class ShapeParserError(Exception):
Expand Down Expand Up @@ -303,7 +303,7 @@ def _get_literal_name(shape: StringShape) -> str:
children_name = "".join(sorted(f"{i[0].upper()}{i[1:]}" for i in shape.enum))
return f"{children_name}Type"

name = shape.name.lstrip("_")
name = capitalize(shape.name.lstrip("_"))
name = f"{name}Type"
return name

Expand Down
12 changes: 10 additions & 2 deletions mypy_boto3_builder/utils/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_class_prefix(func_name: str) -> str:
Returns:
String with a class prefix.
"""
parts = [f"{i[:1].upper()}{i[1:]}" for i in func_name.split("_") if i]
parts = [capitalize(i) for i in func_name.split("_") if i]
return "".join(parts)


Expand Down Expand Up @@ -136,7 +136,8 @@ def get_botocore_class_name(metadata: dict[str, str]) -> str:
service_model = MagicMock()
service_model.service_name = metadata.get("serviceId", "")
service_model.metadata = metadata
return get_service_module_name(service_model)
name = get_service_module_name(service_model)
return capitalize(name)


def get_type_def_name(*parts: str) -> str:
Expand All @@ -154,3 +155,10 @@ def get_type_def_name(*parts: str) -> str:
parts_camelcased = [get_class_prefix(i) for i in parts]
name = "".join(parts_camelcased)
return f"{name}TypeDef"


def capitalize(s: str) -> str:
"""
Capitalize first letter of a string.
"""
return s[:1].upper() + s[1:]
2 changes: 2 additions & 0 deletions scripts/check_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def run_ruff(path: Path) -> None:
"E501",
"N802",
"N803",
"RUF002",
]
with tempfile.NamedTemporaryFile("w+b") as f:
try:
Expand All @@ -150,6 +151,7 @@ def run_ruff(path: Path) -> None:
sys.executable,
"-m",
"ruff",
"check",
"--ignore",
",".join(ignore_errors),
path.as_posix(),
Expand Down
17 changes: 17 additions & 0 deletions tests/utils/test_strings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest

from mypy_boto3_builder.utils.strings import (
capitalize,
get_anchor_link,
get_botocore_class_name,
get_class_prefix,
get_short_docstring,
get_type_def_name,
Expand Down Expand Up @@ -67,3 +69,18 @@ def test_textwrap(self) -> None:
assert textwrap("te st words", 6) == "te\nst\nwords"
assert textwrap("te stwords", 12) == "te stwords"
assert textwrap("te stwords new", 6) == "te\nstwords\nnew"

def test_get_botocore_class_name(self) -> None:
assert get_botocore_class_name({"serviceAbbreviation": "drs"}) == "Drs"
assert (
get_botocore_class_name({"serviceAbbreviation": "drs", "serviceFullName": "name"})
== "Drs"
)
assert get_botocore_class_name({"serviceFullName": "name"}) == "Name"
assert get_botocore_class_name({"serviceFullName": "naMe"}) == "NaMe"
assert get_botocore_class_name({"serviceAbbreviation": "RDS"}) == "RDS"

def test_capitalize(self) -> None:
assert capitalize("test caps") == "Test caps"
assert capitalize("test Caps") == "Test Caps"
assert capitalize("TEST") == "TEST"

0 comments on commit 635aed6

Please sign in to comment.