diff --git a/mypy_boto3_builder/postprocessors/aiobotocore.py b/mypy_boto3_builder/postprocessors/aiobotocore.py index 5f2768fd..47a948e2 100644 --- a/mypy_boto3_builder/postprocessors/aiobotocore.py +++ b/mypy_boto3_builder/postprocessors/aiobotocore.py @@ -34,7 +34,7 @@ class AioBotocorePostprocessor(BasePostprocessor): Postprocessor for aiobotocore classes and methods. """ - _COMMON_COLLECTION_METHOD_NAMES: Final[set[str]] = { + _COMMON_COLLECTION_METHOD_NAMES: Final = { "__iter__", "__aiter__", "all", @@ -43,7 +43,7 @@ class AioBotocorePostprocessor(BasePostprocessor): "limit", "page_size", } - _NOT_ASYNC_METHOD_NAMES: Final[set[str]] = { + _NOT_ASYNC_METHOD_NAMES: Final = { "exceptions", "get_waiter", "get_paginator", diff --git a/mypy_boto3_builder/service_name.py b/mypy_boto3_builder/service_name.py index 30494e66..16474c0e 100644 --- a/mypy_boto3_builder/service_name.py +++ b/mypy_boto3_builder/service_name.py @@ -17,12 +17,12 @@ class ServiceName: Description for boto3 service. """ - ALL: Final[str] = "all" - UPDATED: Final[str] = "updated" - ESSENTIAL: Final[str] = "essential" - LATEST: Final[str] = "latest" + ALL: Final = "all" + UPDATED: Final = "updated" + ESSENTIAL: Final = "essential" + LATEST: Final = "latest" - ESSENTIAL_NAMES: Final[set[str]] = { + ESSENTIAL_NAMES: Final = { "ec2", "rds", "s3", @@ -31,7 +31,7 @@ class ServiceName: "cloudformation", "dynamodb", } - CONDA_FORGE_AVAILABLE: Final[set[str]] = { + CONDA_FORGE_AVAILABLE: Final = { "ec2", "rds", "s3", @@ -57,7 +57,7 @@ def __str__(self) -> str: """ Represent as string for debugging. """ - return f"" + return self.name @property def underscore_name(self) -> str: @@ -168,6 +168,7 @@ class ServiceNameCatalog: cloudsearchdomain = ServiceName("cloudsearchdomain", "CloudSearchDomain") logs = ServiceName("logs", "CloudWatchLogs") lambda_ = ServiceName("lambda", "Lambda") + stepfunctions = ServiceName("stepfunctions", "SFN") old_redshift_serverless = ServiceName( "redshift-serverless", "RedshiftServerless", "redshiftserverless" ) diff --git a/mypy_boto3_builder/structures/argument.py b/mypy_boto3_builder/structures/argument.py index b3e1142e..e4454e70 100644 --- a/mypy_boto3_builder/structures/argument.py +++ b/mypy_boto3_builder/structures/argument.py @@ -21,10 +21,10 @@ class Argument: prefix -- Used for starargs. """ - SELF_NAME: Final[str] = "self" - CLS_NAME: Final[str] = "cls" - KW_NAME: Final[str] = "*" - FIRST_NAMES: Final[set[str]] = {SELF_NAME, CLS_NAME} + SELF_NAME: Final = "self" + CLS_NAME: Final = "cls" + KW_NAME: Final = "*" + FIRST_NAMES: Final = {SELF_NAME, CLS_NAME} def __init__( self, diff --git a/mypy_boto3_builder/structures/client.py b/mypy_boto3_builder/structures/client.py index 8b07b946..bdf27d72 100644 --- a/mypy_boto3_builder/structures/client.py +++ b/mypy_boto3_builder/structures/client.py @@ -25,7 +25,7 @@ class Client(ClassRecord): Service Client. """ - _OWN_METHOD_NAMES: Final[set[str]] = { + _OWN_METHOD_NAMES: Final = { "get_waiter", "get_paginator", "exceptions", diff --git a/mypy_boto3_builder/type_annotations/type_annotation.py b/mypy_boto3_builder/type_annotations/type_annotation.py index e1212f4a..0cc1fd77 100644 --- a/mypy_boto3_builder/type_annotations/type_annotation.py +++ b/mypy_boto3_builder/type_annotations/type_annotation.py @@ -19,8 +19,8 @@ class TypeAnnotation(FakeAnnotation): wrapped_type -- Original type annotation as a string. """ - _TYPING: Final[ImportString] = ImportString("typing") - _TYPING_EXTENSIONS: Final[ImportString] = ImportString("typing_extensions") + _TYPING: Final = ImportString("typing") + _TYPING_EXTENSIONS: Final = ImportString("typing_extensions") # Set of supported type annotations. value is default import module _SUPPORTED_TYPES: Final[Mapping[str, ImportString]] = { diff --git a/mypy_boto3_builder/type_annotations/type_union.py b/mypy_boto3_builder/type_annotations/type_union.py index c42f8e92..e1abb4cc 100644 --- a/mypy_boto3_builder/type_annotations/type_union.py +++ b/mypy_boto3_builder/type_annotations/type_union.py @@ -23,7 +23,7 @@ class TypeUnion(TypeSubscript, TypeDefSortable): Wrapper for name Union type annotations, like `MyUnion = Union[str, int]`. """ - _MIN_CHILDREN: Final[int] = 2 + _MIN_CHILDREN: Final = 2 def __init__( self, diff --git a/mypy_boto3_builder/utils/strings.py b/mypy_boto3_builder/utils/strings.py index c874faf3..ae5b834e 100644 --- a/mypy_boto3_builder/utils/strings.py +++ b/mypy_boto3_builder/utils/strings.py @@ -6,7 +6,6 @@ import keyword import re import typing -from collections.abc import Mapping from types import MappingProxyType from typing import Final from unittest.mock import MagicMock @@ -15,14 +14,14 @@ from mypy_boto3_builder.exceptions import TypeAnnotationError -RESERVED_NAMES: Final[set[str]] = { +RESERVED_NAMES: Final = { *dir(typing), *dir(builtins), *keyword.kwlist, } -MAX_DOCSTRING_LENGTH: Final[int] = 300 -AWS_LINK_RE: Final[re.Pattern[str]] = re.compile(r"`([^`]+\S)\s*`\_*") -REPLACE_DOCSTRING_CHARS: Final[Mapping[str, str]] = MappingProxyType({"’": "'", "–": "-"}) +MAX_DOCSTRING_LENGTH: Final = 300 +AWS_LINK_RE: Final = re.compile(r"`([^`]+\S)\s*`\_*") +REPLACE_DOCSTRING_CHARS: Final = MappingProxyType({"’": "'", "–": "-"}) def get_class_prefix(func_name: str) -> str: diff --git a/mypy_boto3_builder/writers/package_writer.py b/mypy_boto3_builder/writers/package_writer.py index 1daf325f..36044ec3 100644 --- a/mypy_boto3_builder/writers/package_writer.py +++ b/mypy_boto3_builder/writers/package_writer.py @@ -46,8 +46,8 @@ class PackageWriter: cleanup -- Whether to remove unknown files """ - _PY_EXTENSIONS: Final[set[str]] = {".py", ".pyi"} - _MD_EXTENSIONS: Final[set[str]] = {".md"} + _PY_EXTENSIONS: Final = {".py", ".pyi"} + _MD_EXTENSIONS: Final = {".md"} def __init__(self, output_path: Path, generate_setup: bool, cleanup: bool) -> None: self.output_path = output_path diff --git a/tests/utils/test_lookup_dict.py b/tests/utils/test_lookup_dict.py new file mode 100644 index 00000000..436e9886 --- /dev/null +++ b/tests/utils/test_lookup_dict.py @@ -0,0 +1,16 @@ +from mypy_boto3_builder.constants import ALL +from mypy_boto3_builder.utils.lookup_dict import LookupDict + + +class TestLookupDict: + def test_init(self) -> None: + lookup_dict: LookupDict[int] = LookupDict( + {"test": {"one": {"child1": 1}, ALL: {"child2": 10}}, ALL: {"two": {"child3": 12}}} + ) + assert lookup_dict.get("test", "one", "child1") == 1 + assert lookup_dict.get("test", "one", "child2") == 10 + assert lookup_dict.get("test", "one", "child3") is None + assert lookup_dict.get("test", "two", "child1") is None + assert lookup_dict.get("test", "two", "child2") == 10 + assert lookup_dict.get("test2", "two", "child2") is None + assert lookup_dict.get("test2", "two", "child3") == 12