From 19fe439e7b3cee505cbafa035a5a27d997160535 Mon Sep 17 00:00:00 2001 From: Vlad Emelianov Date: Mon, 28 Oct 2024 11:10:35 +0300 Subject: [PATCH] Add is_not_required LookupDict usage --- mypy_boto3_builder/constants.py | 79 ++++++++++------------ mypy_boto3_builder/parsers/shape_parser.py | 4 +- 2 files changed, 36 insertions(+), 47 deletions(-) diff --git a/mypy_boto3_builder/constants.py b/mypy_boto3_builder/constants.py index 5f638911..018912cf 100644 --- a/mypy_boto3_builder/constants.py +++ b/mypy_boto3_builder/constants.py @@ -6,46 +6,37 @@ from typing import Final # Random region to initialize services -DUMMY_REGION: Final[str] = "us-west-2" +DUMMY_REGION: Final = "us-west-2" # Root path for the project -ROOT_PATH: Final[Path] = Path(__file__).parent +ROOT_PATH: Final = Path(__file__).parent # Jinja2 templates for boto3-stubs -TEMPLATES_PATH: Final[Path] = ROOT_PATH / "templates" +TEMPLATES_PATH: Final = ROOT_PATH / "templates" # Max line length for formatting -LINE_LENGTH: Final[int] = 100 +LINE_LENGTH: Final = 100 # mypy-boto3-builder GitHub link -BUILDER_REPO_URL: Final[str] = "https://github.com/youtype/mypy_boto3_builder" +BUILDER_REPO_URL: Final = "https://github.com/youtype/mypy_boto3_builder" # Main logger name -LOGGER_NAME: Final[str] = "mypy_boto3_builder" +LOGGER_NAME: Final = "mypy_boto3_builder" # builder CLI entrypoint name -PROG_NAME: Final[str] = "mypy_boto3_builder" +PROG_NAME: Final = "mypy_boto3_builder" # builder package name -PACKAGE_NAME: Final[str] = "mypy-boto3-builder" +PACKAGE_NAME: Final = "mypy-boto3-builder" # universal mask for all resources -ALL: Final[str] = "*" -ATTRIBUTES: Final[str] = "_attributes" -SERVICE_RESOURCE: Final[str] = "ServiceResource" -CLIENT: Final[str] = "Client" - -# keys to mark as NotRequired for output TypeDicts -NOT_REQUIRED_OUTPUT_KEYS: Final[set[str]] = { - "NextToken", - "nextToken", - "Contents", - "Item", - "CommonPrefixes", -} +ALL: Final = "*" +ATTRIBUTES: Final = "_attributes" +SERVICE_RESOURCE: Final = "ServiceResource" +CLIENT: Final = "Client" # python versions supported by output stubs -SUPPORTED_PY_VERSIONS: Final[set[tuple[int, int]]] = { +SUPPORTED_PY_VERSIONS: Final = { (3, 8), (3, 9), (3, 10), @@ -55,7 +46,7 @@ } # default timeout for HTTP requests -REQUEST_TIMEOUT: Final[int] = 120 +REQUEST_TIMEOUT: Final = 120 class TemplatePath: @@ -63,23 +54,23 @@ class TemplatePath: Template paths. """ - master: Final[Path] = TEMPLATES_PATH / "master" + master: Final = TEMPLATES_PATH / "master" - boto3_stubs: Final[Path] = TEMPLATES_PATH / "boto3-stubs" - boto3_stubs_docs: Final[Path] = TEMPLATES_PATH / "boto3-stubs-docs" - boto3_stubs_service: Final[Path] = TEMPLATES_PATH / "boto3-stubs-service" - boto3_stubs_service_docs: Final[Path] = TEMPLATES_PATH / "boto3-stubs-service-docs" - boto3_stubs_full: Final[Path] = TEMPLATES_PATH / "boto3-stubs-full" + boto3_stubs: Final = TEMPLATES_PATH / "boto3-stubs" + boto3_stubs_docs: Final = TEMPLATES_PATH / "boto3-stubs-docs" + boto3_stubs_service: Final = TEMPLATES_PATH / "boto3-stubs-service" + boto3_stubs_service_docs: Final = TEMPLATES_PATH / "boto3-stubs-service-docs" + boto3_stubs_full: Final = TEMPLATES_PATH / "boto3-stubs-full" - types_aioboto3: Final[Path] = TEMPLATES_PATH / "types-aioboto3" - types_aioboto3_docs: Final[Path] = TEMPLATES_PATH / "types-aioboto3-docs" - types_aioboto3_service_docs: Final[Path] = TEMPLATES_PATH / "types-aioboto3-service-docs" + types_aioboto3: Final = TEMPLATES_PATH / "types-aioboto3" + types_aioboto3_docs: Final = TEMPLATES_PATH / "types-aioboto3-docs" + types_aioboto3_service_docs: Final = TEMPLATES_PATH / "types-aioboto3-service-docs" - types_aiobotocore: Final[Path] = TEMPLATES_PATH / "types-aiobotocore" - types_aiobotocore_docs: Final[Path] = TEMPLATES_PATH / "types-aiobotocore-docs" - types_aiobotocore_service: Final[Path] = TEMPLATES_PATH / "types-aiobotocore-service" - types_aiobotocore_service_docs: Final[Path] = TEMPLATES_PATH / "types-aiobotocore-service-docs" - types_aiobotocore_full: Final[Path] = TEMPLATES_PATH / "types-aiobotocore-full" + types_aiobotocore: Final = TEMPLATES_PATH / "types-aiobotocore" + types_aiobotocore_docs: Final = TEMPLATES_PATH / "types-aiobotocore-docs" + types_aiobotocore_service: Final = TEMPLATES_PATH / "types-aiobotocore-service" + types_aiobotocore_service_docs: Final = TEMPLATES_PATH / "types-aiobotocore-service-docs" + types_aiobotocore_full: Final = TEMPLATES_PATH / "types-aiobotocore-full" class StaticStubsPath: @@ -87,9 +78,9 @@ class StaticStubsPath: Static *.pyi files path. """ - boto3_stubs: Final[Path] = ROOT_PATH / "stubs_static" / "boto3-stubs" - types_aiobotocore: Final[Path] = ROOT_PATH / "stubs_static" / "types-aiobotocore" - types_aioboto3: Final[Path] = ROOT_PATH / "stubs_static" / "types-aioboto3" + boto3_stubs: Final = ROOT_PATH / "stubs_static" / "boto3-stubs" + types_aiobotocore: Final = ROOT_PATH / "stubs_static" / "types-aiobotocore" + types_aioboto3: Final = ROOT_PATH / "stubs_static" / "types-aioboto3" class StaticStubsPullURL: @@ -97,8 +88,6 @@ class StaticStubsPullURL: Static *.pyi files zip download URL. """ - boto3_stubs: Final[str] = "https://api.github.com/repos/youtype/boto3-stubs/zipball/main" - types_aiobotocore: Final[str] = ( - "https://api.github.com/repos/youtype/types-aiobotocore/zipball/main" - ) - types_aioboto3: Final[str] = "https://api.github.com/repos/youtype/types-aioboto3/zipball/main" + boto3_stubs: Final = "https://api.github.com/repos/youtype/boto3-stubs/zipball/main" + types_aiobotocore: Final = "https://api.github.com/repos/youtype/types-aiobotocore/zipball/main" + types_aioboto3: Final = "https://api.github.com/repos/youtype/types-aioboto3/zipball/main" diff --git a/mypy_boto3_builder/parsers/shape_parser.py b/mypy_boto3_builder/parsers/shape_parser.py index 195e612f..8707d9c4 100644 --- a/mypy_boto3_builder/parsers/shape_parser.py +++ b/mypy_boto3_builder/parsers/shape_parser.py @@ -24,7 +24,6 @@ from mypy_boto3_builder.constants import ( ATTRIBUTES, CLIENT, - NOT_REQUIRED_OUTPUT_KEYS, SERVICE_RESOURCE, ) from mypy_boto3_builder.exceptions import ShapeParserError @@ -59,6 +58,7 @@ get_default_value_stub, get_method_type_stub, ) +from mypy_boto3_builder.type_maps.not_required_attribute_map import is_not_required from mypy_boto3_builder.type_maps.shape_type_map import ( OUTPUT_SHAPE_TYPE_MAP, SHAPE_TYPE_MAP, @@ -430,7 +430,7 @@ def _parse_shape_structure( def _mark_typed_dict_as_total(self, typed_dict: TypeTypedDict) -> None: for attribute in typed_dict.children: - if attribute.name not in NOT_REQUIRED_OUTPUT_KEYS: + if is_not_required(self.service_name, typed_dict.name, attribute.name): attribute.mark_as_required() def _add_response_metadata(self, typed_dict: TypeTypedDict) -> None: