Skip to content

Commit

Permalink
Refactor all Final
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Oct 28, 2024
1 parent 19fe439 commit 17ce0cd
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 24 deletions.
4 changes: 2 additions & 2 deletions mypy_boto3_builder/postprocessors/aiobotocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand 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",
Expand Down
15 changes: 8 additions & 7 deletions mypy_boto3_builder/service_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -31,7 +31,7 @@ class ServiceName:
"cloudformation",
"dynamodb",
}
CONDA_FORGE_AVAILABLE: Final[set[str]] = {
CONDA_FORGE_AVAILABLE: Final = {
"ec2",
"rds",
"s3",
Expand All @@ -57,7 +57,7 @@ def __str__(self) -> str:
"""
Represent as string for debugging.
"""
return f"<ServiceName {self.name} {self.class_name}>"
return self.name

@property
def underscore_name(self) -> str:
Expand Down Expand Up @@ -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"
)
Expand Down
8 changes: 4 additions & 4 deletions mypy_boto3_builder/structures/argument.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mypy_boto3_builder/structures/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Client(ClassRecord):
Service Client.
"""

_OWN_METHOD_NAMES: Final[set[str]] = {
_OWN_METHOD_NAMES: Final = {
"get_waiter",
"get_paginator",
"exceptions",
Expand Down
4 changes: 2 additions & 2 deletions mypy_boto3_builder/type_annotations/type_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = {
Expand Down
2 changes: 1 addition & 1 deletion mypy_boto3_builder/type_annotations/type_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions mypy_boto3_builder/utils/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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*<https://(\S+)>`\_*")
REPLACE_DOCSTRING_CHARS: Final[Mapping[str, str]] = MappingProxyType({"’": "'", "–": "-"})
MAX_DOCSTRING_LENGTH: Final = 300
AWS_LINK_RE: Final = re.compile(r"`([^`]+\S)\s*<https://(\S+)>`\_*")
REPLACE_DOCSTRING_CHARS: Final = MappingProxyType({"’": "'", "–": "-"})


def get_class_prefix(func_name: str) -> str:
Expand Down
4 changes: 2 additions & 2 deletions mypy_boto3_builder/writers/package_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions tests/utils/test_lookup_dict.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 17ce0cd

Please sign in to comment.