From 5b87bb195fb154d2a112364a5d1d5c9513898e55 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Fri, 16 Jul 2021 11:34:45 -0700 Subject: [PATCH] fix(mypy): fixes to resolve no implicit optional errors (#521) --- .../event_handler/api_gateway.py | 37 ++++++++++---- .../event_handler/appsync.py | 4 +- aws_lambda_powertools/logging/formatter.py | 4 +- aws_lambda_powertools/logging/logger.py | 22 ++++---- aws_lambda_powertools/metrics/base.py | 16 +++--- aws_lambda_powertools/metrics/metric.py | 2 +- aws_lambda_powertools/metrics/metrics.py | 6 +-- .../middleware_factory/factory.py | 8 +-- aws_lambda_powertools/shared/functions.py | 4 +- aws_lambda_powertools/tracing/base.py | 8 +-- aws_lambda_powertools/tracing/tracer.py | 51 ++++++++++--------- .../utilities/idempotency/config.py | 4 +- .../utilities/idempotency/idempotency.py | 2 +- .../utilities/idempotency/persistence/base.py | 4 +- .../idempotency/persistence/dynamodb.py | 2 +- .../utilities/validation/base.py | 4 +- .../utilities/validation/validator.py | 12 ++--- mypy.ini | 15 ++++++ 18 files changed, 121 insertions(+), 84 deletions(-) diff --git a/aws_lambda_powertools/event_handler/api_gateway.py b/aws_lambda_powertools/event_handler/api_gateway.py index b6e9cd4698b..8b6c368af33 100644 --- a/aws_lambda_powertools/event_handler/api_gateway.py +++ b/aws_lambda_powertools/event_handler/api_gateway.py @@ -126,7 +126,11 @@ class Response: """Response data class that provides greater control over what is returned from the proxy event""" def __init__( - self, status_code: int, content_type: Optional[str], body: Union[str, bytes, None], headers: Dict = None + self, + status_code: int, + content_type: Optional[str], + body: Union[str, bytes, None], + headers: Optional[Dict] = None, ): """ @@ -167,7 +171,7 @@ def __init__( class ResponseBuilder: """Internally used Response builder""" - def __init__(self, response: Response, route: Route = None): + def __init__(self, response: Response, route: Optional[Route] = None): self.response = response self.route = route @@ -199,7 +203,7 @@ def _route(self, event: BaseProxyEvent, cors: Optional[CORSConfig]): if self.route.compress and "gzip" in (event.get_header_value("accept-encoding", "") or ""): self._compress() - def build(self, event: BaseProxyEvent, cors: CORSConfig = None) -> Dict[str, Any]: + def build(self, event: BaseProxyEvent, cors: Optional[CORSConfig] = None) -> Dict[str, Any]: """Build the full response dict to be returned by the lambda""" self._route(event, cors) @@ -250,7 +254,7 @@ def lambda_handler(event, context): def __init__( self, proxy_type: Enum = ProxyEventType.APIGatewayProxyEvent, - cors: CORSConfig = None, + cors: Optional[CORSConfig] = None, debug: Optional[bool] = None, ): """ @@ -270,10 +274,10 @@ def __init__( self._cors_enabled: bool = cors is not None self._cors_methods: Set[str] = {"OPTIONS"} self._debug = resolve_truthy_env_var_choice( - choice=debug, env=os.getenv(constants.EVENT_HANDLER_DEBUG_ENV, "false") + env=os.getenv(constants.EVENT_HANDLER_DEBUG_ENV, "false"), choice=debug ) - def get(self, rule: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def get(self, rule: str, cors: Optional[bool] = None, compress: bool = False, cache_control: Optional[str] = None): """Get route decorator with GET `method` Examples @@ -298,7 +302,7 @@ def lambda_handler(event, context): """ return self.route(rule, "GET", cors, compress, cache_control) - def post(self, rule: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def post(self, rule: str, cors: Optional[bool] = None, compress: bool = False, cache_control: Optional[str] = None): """Post route decorator with POST `method` Examples @@ -324,7 +328,7 @@ def lambda_handler(event, context): """ return self.route(rule, "POST", cors, compress, cache_control) - def put(self, rule: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def put(self, rule: str, cors: Optional[bool] = None, compress: bool = False, cache_control: Optional[str] = None): """Put route decorator with PUT `method` Examples @@ -350,7 +354,9 @@ def lambda_handler(event, context): """ return self.route(rule, "PUT", cors, compress, cache_control) - def delete(self, rule: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def delete( + self, rule: str, cors: Optional[bool] = None, compress: bool = False, cache_control: Optional[str] = None + ): """Delete route decorator with DELETE `method` Examples @@ -375,7 +381,9 @@ def lambda_handler(event, context): """ return self.route(rule, "DELETE", cors, compress, cache_control) - def patch(self, rule: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def patch( + self, rule: str, cors: Optional[bool] = None, compress: bool = False, cache_control: Optional[str] = None + ): """Patch route decorator with PATCH `method` Examples @@ -403,7 +411,14 @@ def lambda_handler(event, context): """ return self.route(rule, "PATCH", cors, compress, cache_control) - def route(self, rule: str, method: str, cors: bool = None, compress: bool = False, cache_control: str = None): + def route( + self, + rule: str, + method: str, + cors: Optional[bool] = None, + compress: bool = False, + cache_control: Optional[str] = None, + ): """Route decorator includes parameter `method`""" def register_resolver(func: Callable): diff --git a/aws_lambda_powertools/event_handler/appsync.py b/aws_lambda_powertools/event_handler/appsync.py index 021afaa6654..7f4cce5c8bf 100644 --- a/aws_lambda_powertools/event_handler/appsync.py +++ b/aws_lambda_powertools/event_handler/appsync.py @@ -1,5 +1,5 @@ import logging -from typing import Any, Callable +from typing import Any, Callable, Optional from aws_lambda_powertools.utilities.data_classes import AppSyncResolverEvent from aws_lambda_powertools.utilities.typing import LambdaContext @@ -44,7 +44,7 @@ def common_field() -> str: def __init__(self): self._resolvers: dict = {} - def resolver(self, type_name: str = "*", field_name: str = None): + def resolver(self, type_name: str = "*", field_name: Optional[str] = None): """Registers the resolver for field_name Parameters diff --git a/aws_lambda_powertools/logging/formatter.py b/aws_lambda_powertools/logging/formatter.py index 7ff9881062a..de9254a3371 100644 --- a/aws_lambda_powertools/logging/formatter.py +++ b/aws_lambda_powertools/logging/formatter.py @@ -60,8 +60,8 @@ def __init__( json_serializer: Optional[Callable[[Dict], str]] = None, json_deserializer: Optional[Callable[[Dict], str]] = None, json_default: Optional[Callable[[Any], Any]] = None, - datefmt: str = None, - log_record_order: List[str] = None, + datefmt: Optional[str] = None, + log_record_order: Optional[List[str]] = None, utc: bool = False, **kwargs ): diff --git a/aws_lambda_powertools/logging/logger.py b/aws_lambda_powertools/logging/logger.py index 72e22b38c7f..8ac911d4cac 100644 --- a/aws_lambda_powertools/logging/logger.py +++ b/aws_lambda_powertools/logging/logger.py @@ -167,11 +167,11 @@ class Logger(logging.Logger): # lgtm [py/missing-call-to-init] def __init__( self, - service: str = None, - level: Union[str, int] = None, + service: Optional[str] = None, + level: Union[str, int, None] = None, child: bool = False, - sampling_rate: float = None, - stream: IO[str] = None, + sampling_rate: Optional[float] = None, + stream: Optional[IO[str]] = None, logger_formatter: Optional[PowertoolsFormatter] = None, logger_handler: Optional[logging.Handler] = None, **kwargs, @@ -261,10 +261,10 @@ def _configure_sampling(self): def inject_lambda_context( self, - lambda_handler: Callable[[Dict, Any], Any] = None, - log_event: bool = None, - correlation_id_path: str = None, - clear_state: bool = False, + lambda_handler: Optional[Callable[[Dict, Any], Any]] = None, + log_event: Optional[bool] = None, + correlation_id_path: Optional[str] = None, + clear_state: Optional[bool] = False, ): """Decorator to capture Lambda contextual info and inject into logger @@ -324,7 +324,7 @@ def handler(event, context): ) log_event = resolve_truthy_env_var_choice( - choice=log_event, env=os.getenv(constants.LOGGER_LOG_EVENT_ENV, "false") + env=os.getenv(constants.LOGGER_LOG_EVENT_ENV, "false"), choice=log_event ) @functools.wraps(lambda_handler) @@ -421,7 +421,9 @@ def _get_caller_filename(): def set_package_logger( - level: Union[str, int] = logging.DEBUG, stream: IO[str] = None, formatter: logging.Formatter = None + level: Union[str, int] = logging.DEBUG, + stream: Optional[IO[str]] = None, + formatter: Optional[logging.Formatter] = None, ): """Set an additional stream handler, formatter, and log level for aws_lambda_powertools package logger. diff --git a/aws_lambda_powertools/metrics/base.py b/aws_lambda_powertools/metrics/base.py index dc4fe34ee12..853f06f210b 100644 --- a/aws_lambda_powertools/metrics/base.py +++ b/aws_lambda_powertools/metrics/base.py @@ -5,7 +5,7 @@ import os from collections import defaultdict from enum import Enum -from typing import Any, Dict, List, Union +from typing import Any, Dict, List, Optional, Union from ..shared import constants from ..shared.functions import resolve_env_var_choice @@ -76,11 +76,11 @@ class MetricManager: def __init__( self, - metric_set: Dict[str, Any] = None, - dimension_set: Dict = None, - namespace: str = None, - metadata_set: Dict[str, Any] = None, - service: str = None, + metric_set: Optional[Dict[str, Any]] = None, + dimension_set: Optional[Dict] = None, + namespace: Optional[str] = None, + metadata_set: Optional[Dict[str, Any]] = None, + service: Optional[str] = None, ): self.metric_set = metric_set if metric_set is not None else {} self.dimension_set = dimension_set if dimension_set is not None else {} @@ -136,7 +136,9 @@ def add_metric(self, name: str, unit: Union[MetricUnit, str], value: float): # since we could have more than 100 metrics self.metric_set.clear() - def serialize_metric_set(self, metrics: Dict = None, dimensions: Dict = None, metadata: Dict = None) -> Dict: + def serialize_metric_set( + self, metrics: Optional[Dict] = None, dimensions: Optional[Dict] = None, metadata: Optional[Dict] = None + ) -> Dict: """Serializes metric and dimensions set Parameters diff --git a/aws_lambda_powertools/metrics/metric.py b/aws_lambda_powertools/metrics/metric.py index 8bdd0d800b8..1ac2bd9450e 100644 --- a/aws_lambda_powertools/metrics/metric.py +++ b/aws_lambda_powertools/metrics/metric.py @@ -61,7 +61,7 @@ def add_metric(self, name: str, unit: Union[MetricUnit, str], value: float): @contextmanager -def single_metric(name: str, unit: MetricUnit, value: float, namespace: str = None): +def single_metric(name: str, unit: MetricUnit, value: float, namespace: Optional[str] = None): """Context manager to simplify creation of a single metric Example diff --git a/aws_lambda_powertools/metrics/metrics.py b/aws_lambda_powertools/metrics/metrics.py index 8cc4895f03e..fafc604b505 100644 --- a/aws_lambda_powertools/metrics/metrics.py +++ b/aws_lambda_powertools/metrics/metrics.py @@ -71,7 +71,7 @@ def lambda_handler(): _metadata: Dict[str, Any] = {} _default_dimensions: Dict[str, Any] = {} - def __init__(self, service: str = None, namespace: str = None): + def __init__(self, service: Optional[str] = None, namespace: Optional[str] = None): self.metric_set = self._metrics self.service = service self.namespace: Optional[str] = namespace @@ -125,10 +125,10 @@ def clear_metrics(self): def log_metrics( self, - lambda_handler: Callable[[Any, Any], Any] = None, + lambda_handler: Optional[Callable[[Any, Any], Any]] = None, capture_cold_start_metric: bool = False, raise_on_empty_metrics: bool = False, - default_dimensions: Dict[str, str] = None, + default_dimensions: Optional[Dict[str, str]] = None, ): """Decorator to serialize and publish metrics at the end of a function execution. diff --git a/aws_lambda_powertools/middleware_factory/factory.py b/aws_lambda_powertools/middleware_factory/factory.py index 77277052272..74858bf6709 100644 --- a/aws_lambda_powertools/middleware_factory/factory.py +++ b/aws_lambda_powertools/middleware_factory/factory.py @@ -2,7 +2,7 @@ import inspect import logging import os -from typing import Callable +from typing import Callable, Optional from ..shared import constants from ..shared.functions import resolve_truthy_env_var_choice @@ -12,7 +12,7 @@ logger = logging.getLogger(__name__) -def lambda_handler_decorator(decorator: Callable = None, trace_execution: bool = None): +def lambda_handler_decorator(decorator: Optional[Callable] = None, trace_execution: Optional[bool] = None): """Decorator factory for decorating Lambda handlers. You can use lambda_handler_decorator to create your own middlewares, @@ -106,11 +106,11 @@ def lambda_handler(event, context): return functools.partial(lambda_handler_decorator, trace_execution=trace_execution) trace_execution = resolve_truthy_env_var_choice( - choice=trace_execution, env=os.getenv(constants.MIDDLEWARE_FACTORY_TRACE_ENV, "false") + env=os.getenv(constants.MIDDLEWARE_FACTORY_TRACE_ENV, "false"), choice=trace_execution ) @functools.wraps(decorator) - def final_decorator(func: Callable = None, **kwargs): + def final_decorator(func: Optional[Callable] = None, **kwargs): # If called with kwargs return new func with kwargs if func is None: return functools.partial(final_decorator, **kwargs) diff --git a/aws_lambda_powertools/shared/functions.py b/aws_lambda_powertools/shared/functions.py index b8f5cb9f74b..0b117cc32bb 100644 --- a/aws_lambda_powertools/shared/functions.py +++ b/aws_lambda_powertools/shared/functions.py @@ -2,14 +2,14 @@ from typing import Any, Optional, Union -def resolve_truthy_env_var_choice(env: Any, choice: bool = None) -> bool: +def resolve_truthy_env_var_choice(env: str, choice: Optional[bool] = None) -> bool: """Pick explicit choice over truthy env value, if available, otherwise return truthy env value NOTE: Environment variable should be resolved by the caller. Parameters ---------- - env : Any + env : str environment variable actual value choice : bool explicit choice diff --git a/aws_lambda_powertools/tracing/base.py b/aws_lambda_powertools/tracing/base.py index 1857ed52a73..722652ce08b 100644 --- a/aws_lambda_powertools/tracing/base.py +++ b/aws_lambda_powertools/tracing/base.py @@ -2,11 +2,11 @@ import numbers import traceback from contextlib import contextmanager -from typing import Any, AsyncContextManager, ContextManager, List, NoReturn, Set, Union +from typing import Any, AsyncContextManager, ContextManager, List, NoReturn, Optional, Set, Union class BaseProvider(abc.ABC): - @abc.abstractmethod + @abc.abstractmethod # type: ignore @contextmanager def in_subsegment(self, name=None, **kwargs) -> ContextManager: """Return a subsegment context manger. @@ -19,7 +19,7 @@ def in_subsegment(self, name=None, **kwargs) -> ContextManager: Optional parameters to be propagated to segment """ - @abc.abstractmethod + @abc.abstractmethod # type: ignore @contextmanager def in_subsegment_async(self, name=None, **kwargs) -> AsyncContextManager: """Return a subsegment async context manger. @@ -81,7 +81,7 @@ class BaseSegment(abc.ABC): """Holds common properties and methods on segment and subsegment.""" @abc.abstractmethod - def close(self, end_time: int = None): + def close(self, end_time: Optional[int] = None): """Close the trace entity by setting `end_time` and flip the in progress flag to False. diff --git a/aws_lambda_powertools/tracing/tracer.py b/aws_lambda_powertools/tracing/tracer.py index 47568802202..48b7866cf0a 100644 --- a/aws_lambda_powertools/tracing/tracer.py +++ b/aws_lambda_powertools/tracing/tracer.py @@ -5,7 +5,7 @@ import logging import numbers import os -from typing import Any, Callable, Dict, List, Optional, Tuple, Union +from typing import Any, Callable, Dict, Optional, Sequence, Union from ..shared import constants from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice @@ -53,7 +53,7 @@ class Tracer: disabled: bool Flag to explicitly disable tracing, useful when running/testing locally `Env POWERTOOLS_TRACE_DISABLED="true"` - patch_modules: Tuple[str] + patch_modules: Optional[Sequence[str]] Tuple of modules supported by tracing provider to patch, by default all modules are patched provider: BaseProvider Tracing provider, by default it is aws_xray_sdk.core.xray_recorder @@ -146,11 +146,11 @@ def handler(event: dict, context: Any) -> Dict: def __init__( self, - service: str = None, - disabled: bool = None, - auto_patch: bool = None, - patch_modules: Optional[Tuple[str]] = None, - provider: BaseProvider = None, + service: Optional[str] = None, + disabled: Optional[bool] = None, + auto_patch: Optional[bool] = None, + patch_modules: Optional[Sequence[str]] = None, + provider: Optional[BaseProvider] = None, ): self.__build_config( service=service, disabled=disabled, auto_patch=auto_patch, patch_modules=patch_modules, provider=provider @@ -195,7 +195,7 @@ def put_annotation(self, key: str, value: Union[str, numbers.Number, bool]): logger.debug(f"Annotating on key '{key}' with '{value}'") self.provider.put_annotation(key=key, value=value) - def put_metadata(self, key: str, value: Any, namespace: str = None): + def put_metadata(self, key: str, value: Any, namespace: Optional[str] = None): """Adds metadata to existing segment or subsegment Parameters @@ -223,14 +223,14 @@ def put_metadata(self, key: str, value: Any, namespace: str = None): logger.debug(f"Adding metadata on key '{key}' with '{value}' at namespace '{namespace}'") self.provider.put_metadata(key=key, value=value, namespace=namespace) - def patch(self, modules: Tuple[str] = None): + def patch(self, modules: Optional[Sequence[str]] = None): """Patch modules for instrumentation. Patches all supported modules by default if none are given. Parameters ---------- - modules : Tuple[str] + modules : Optional[Sequence[str]] List of modules to be patched, optional by default """ if self.disabled: @@ -244,7 +244,7 @@ def patch(self, modules: Tuple[str] = None): def capture_lambda_handler( self, - lambda_handler: Union[Callable[[Dict, Any], Any], Callable[[Dict, Any, Optional[Dict]], Any]] = None, + lambda_handler: Union[Callable[[Dict, Any], Any], Optional[Callable[[Dict, Any, Optional[Dict]], Any]]] = None, capture_response: Optional[bool] = None, capture_error: Optional[bool] = None, ): @@ -330,7 +330,10 @@ def decorate(event, context, **kwargs): return decorate def capture_method( - self, method: Callable = None, capture_response: Optional[bool] = None, capture_error: Optional[bool] = None + self, + method: Optional[Callable] = None, + capture_response: Optional[bool] = None, + capture_error: Optional[bool] = None, ): """Decorator to create subsegment for arbitrary functions @@ -520,7 +523,7 @@ def _decorate_async_function( method: Callable, capture_response: Optional[Union[bool, str]] = None, capture_error: Optional[Union[bool, str]] = None, - method_name: str = None, + method_name: Optional[str] = None, ): @functools.wraps(method) async def decorate(*args, **kwargs): @@ -547,7 +550,7 @@ def _decorate_generator_function( method: Callable, capture_response: Optional[Union[bool, str]] = None, capture_error: Optional[Union[bool, str]] = None, - method_name: str = None, + method_name: Optional[str] = None, ): @functools.wraps(method) def decorate(*args, **kwargs): @@ -574,7 +577,7 @@ def _decorate_generator_function_with_context_manager( method: Callable, capture_response: Optional[Union[bool, str]] = None, capture_error: Optional[Union[bool, str]] = None, - method_name: str = None, + method_name: Optional[str] = None, ): @functools.wraps(method) @contextlib.contextmanager @@ -602,7 +605,7 @@ def _decorate_sync_function( method: Callable, capture_response: Optional[Union[bool, str]] = None, capture_error: Optional[Union[bool, str]] = None, - method_name: str = None, + method_name: Optional[str] = None, ): @functools.wraps(method) def decorate(*args, **kwargs): @@ -629,9 +632,9 @@ def decorate(*args, **kwargs): def _add_response_as_metadata( self, - method_name: str = None, - data: Any = None, - subsegment: BaseSegment = None, + method_name: Optional[str] = None, + data: Optional[Any] = None, + subsegment: Optional[BaseSegment] = None, capture_response: Optional[Union[bool, str]] = None, ): """Add response as metadata for given subsegment @@ -714,11 +717,11 @@ def _is_tracer_disabled() -> Union[bool, str]: def __build_config( self, - service: str = None, - disabled: bool = None, - auto_patch: bool = None, - patch_modules: Union[List, Tuple] = None, - provider: BaseProvider = None, + service: Optional[str] = None, + disabled: Optional[bool] = None, + auto_patch: Optional[bool] = None, + patch_modules: Optional[Sequence[str]] = None, + provider: Optional[BaseProvider] = None, ): """Populates Tracer config for new and existing initializations""" is_disabled = disabled if disabled is not None else self._is_tracer_disabled() diff --git a/aws_lambda_powertools/utilities/idempotency/config.py b/aws_lambda_powertools/utilities/idempotency/config.py index 52afb3bad8c..06468cc74a7 100644 --- a/aws_lambda_powertools/utilities/idempotency/config.py +++ b/aws_lambda_powertools/utilities/idempotency/config.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, Optional class IdempotencyConfig: @@ -6,7 +6,7 @@ def __init__( self, event_key_jmespath: str = "", payload_validation_jmespath: str = "", - jmespath_options: Dict = None, + jmespath_options: Optional[Dict] = None, raise_on_no_idempotency_key: bool = False, expires_after_seconds: int = 60 * 60, # 1 hour default use_local_cache: bool = False, diff --git a/aws_lambda_powertools/utilities/idempotency/idempotency.py b/aws_lambda_powertools/utilities/idempotency/idempotency.py index 6f73a842af4..c2bcc62fd69 100644 --- a/aws_lambda_powertools/utilities/idempotency/idempotency.py +++ b/aws_lambda_powertools/utilities/idempotency/idempotency.py @@ -31,7 +31,7 @@ def idempotent( event: Dict[str, Any], context: LambdaContext, persistence_store: BasePersistenceLayer, - config: IdempotencyConfig = None, + config: Optional[IdempotencyConfig] = None, ) -> Any: """ Middleware to handle idempotency diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/base.py b/aws_lambda_powertools/utilities/idempotency/persistence/base.py index 31aef6dc0f2..eb43a8b30c5 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/base.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/base.py @@ -39,9 +39,9 @@ def __init__( self, idempotency_key, status: str = "", - expiry_timestamp: int = None, + expiry_timestamp: Optional[int] = None, response_data: Optional[str] = "", - payload_hash: str = None, + payload_hash: Optional[str] = None, ) -> None: """ diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py b/aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py index dc00334277e..ae3a1be490f 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py @@ -154,7 +154,7 @@ def _update_record(self, data_record: DataRecord): "ExpressionAttributeNames": expression_attr_names, } - self.table.update_item(**kwargs) + self.table.update_item(**kwargs) # type: ignore def _delete_record(self, data_record: DataRecord) -> None: logger.debug(f"Deleting record for idempotency key: {data_record.idempotency_key}") diff --git a/aws_lambda_powertools/utilities/validation/base.py b/aws_lambda_powertools/utilities/validation/base.py index ec63e39eb3c..b818f11a40e 100644 --- a/aws_lambda_powertools/utilities/validation/base.py +++ b/aws_lambda_powertools/utilities/validation/base.py @@ -1,9 +1,9 @@ import logging from typing import Any, Dict, Optional, Union -import fastjsonschema +import fastjsonschema # type: ignore import jmespath -from jmespath.exceptions import LexerError +from jmespath.exceptions import LexerError # type: ignore from aws_lambda_powertools.shared.jmespath_functions import PowertoolsFunctions diff --git a/aws_lambda_powertools/utilities/validation/validator.py b/aws_lambda_powertools/utilities/validation/validator.py index 3628d486eb3..0497a49a714 100644 --- a/aws_lambda_powertools/utilities/validation/validator.py +++ b/aws_lambda_powertools/utilities/validation/validator.py @@ -12,12 +12,12 @@ def validator( handler: Callable, event: Union[Dict, str], context: Any, - inbound_schema: Dict = None, + inbound_schema: Optional[Dict] = None, inbound_formats: Optional[Dict] = None, - outbound_schema: Dict = None, + outbound_schema: Optional[Dict] = None, outbound_formats: Optional[Dict] = None, - envelope: str = None, - jmespath_options: Dict = None, + envelope: Optional[str] = None, + jmespath_options: Optional[Dict] = None, ) -> Any: """Lambda handler decorator to validate incoming/outbound data using a JSON Schema @@ -135,8 +135,8 @@ def validate( event: Any, schema: Dict, formats: Optional[Dict] = None, - envelope: str = None, - jmespath_options: Dict = None, + envelope: Optional[str] = None, + jmespath_options: Optional[Dict] = None, ): """Standalone function to validate event data using a JSON Schema diff --git a/mypy.ini b/mypy.ini index 42185a692ad..66bed405f59 100644 --- a/mypy.ini +++ b/mypy.ini @@ -11,3 +11,18 @@ show_error_context = True [mypy-jmespath] ignore_missing_imports=True + +[mypy-boto3] +ignore_missing_imports = True + +[mypy-boto3.dynamodb.conditions] +ignore_missing_imports = True + +[mypy-botocore.config] +ignore_missing_imports = True + +[mypy-botocore.exceptions] +ignore_missing_imports = True + +[mypy-aws_xray_sdk.ext.aiohttp.client] +ignore_missing_imports = True