Skip to content

Commit

Permalink
Add is_not_required LookupDict usage
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Oct 28, 2024
1 parent eb5ed2b commit 19fe439
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 47 deletions.
79 changes: 34 additions & 45 deletions mypy_boto3_builder/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -55,50 +46,48 @@
}

# default timeout for HTTP requests
REQUEST_TIMEOUT: Final[int] = 120
REQUEST_TIMEOUT: Final = 120


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:
"""
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:
"""
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"
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 @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 19fe439

Please sign in to comment.