Skip to content

Commit f10cc4e

Browse files
author
Michael Brewer
committed
feat(mypy): add mypy support
1 parent cc128ad commit f10cc4e

File tree

14 files changed

+76
-30
lines changed

14 files changed

+76
-30
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ release: pr
8383
changelog:
8484
@echo "[+] Pre-generating CHANGELOG for tag: $$(git describe --abbrev=0 --tag)"
8585
docker run -v "${PWD}":/workdir quay.io/git-chglog/git-chglog $$(git describe --abbrev=0 --tag).. > TMP_CHANGELOG.md
86+
87+
mypy:
88+
poetry run mypy aws_lambda_powertools

aws_lambda_powertools/logging/logger.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import os
55
import random
66
import sys
7-
from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union
7+
from typing import IO, Any, Callable, Dict, Iterable, Optional, TypeVar, Union
88

9-
import jmespath
9+
import jmespath # type: ignore
1010

1111
from ..shared import constants
1212
from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
@@ -171,7 +171,7 @@ def __init__(
171171
level: Union[str, int] = None,
172172
child: bool = False,
173173
sampling_rate: float = None,
174-
stream: sys.stdout = None,
174+
stream: IO[str] = None,
175175
logger_formatter: Optional[PowertoolsFormatter] = None,
176176
logger_handler: Optional[logging.Handler] = None,
177177
**kwargs,
@@ -363,7 +363,7 @@ def registered_handler(self) -> logging.Handler:
363363
@property
364364
def registered_formatter(self) -> Optional[PowertoolsFormatter]:
365365
"""Convenience property to access logger formatter"""
366-
return self.registered_handler.formatter
366+
return self.registered_handler.formatter # type: ignore
367367

368368
def structure_logs(self, append: bool = False, **keys):
369369
"""Sets logging formatting to JSON.
@@ -384,7 +384,7 @@ def structure_logs(self, append: bool = False, **keys):
384384
self.append_keys(**keys)
385385
else:
386386
log_keys = {**self._default_log_keys, **keys}
387-
formatter = self.logger_formatter or LambdaPowertoolsFormatter(**log_keys)
387+
formatter = self.logger_formatter or LambdaPowertoolsFormatter(**log_keys) # type: ignore
388388
self.registered_handler.setFormatter(formatter)
389389

390390
def set_correlation_id(self, value: str):
@@ -421,7 +421,7 @@ def _get_caller_filename():
421421

422422

423423
def set_package_logger(
424-
level: Union[str, int] = logging.DEBUG, stream: sys.stdout = None, formatter: logging.Formatter = None
424+
level: Union[str, int] = logging.DEBUG, stream: IO[str] = None, formatter: logging.Formatter = None
425425
):
426426
"""Set an additional stream handler, formatter, and log level for aws_lambda_powertools package logger.
427427

aws_lambda_powertools/shared/jmespath_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import gzip
33
import json
44

5-
import jmespath
5+
import jmespath # type: ignore
66

77

88
class PowertoolsFunctions(jmespath.functions.Functions):

aws_lambda_powertools/utilities/batch/sqs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import sys
88
from typing import Callable, Dict, List, Optional, Tuple
99

10-
import boto3
11-
from botocore.config import Config
10+
import boto3 # type: ignore
11+
from botocore.config import Config # type: ignore
1212

1313
from ...middleware_factory import lambda_handler_decorator
1414
from .base import BasePartialProcessor

aws_lambda_powertools/utilities/data_classes/code_pipeline_job_event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, Dict, List, Optional
55
from urllib.parse import unquote_plus
66

7-
import boto3
7+
import boto3 # type: ignore
88

99
from aws_lambda_powertools.utilities.data_classes.common import DictWrapper
1010

aws_lambda_powertools/utilities/idempotency/persistence/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from types import MappingProxyType
1212
from typing import Any, Dict, Optional
1313

14-
import jmespath
14+
import jmespath # type: ignore
1515

1616
from aws_lambda_powertools.shared.cache_dict import LRUDict
1717
from aws_lambda_powertools.shared.jmespath_functions import PowertoolsFunctions

aws_lambda_powertools/utilities/idempotency/persistence/dynamodb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import logging
33
from typing import Any, Dict, Optional
44

5-
import boto3
6-
from botocore.config import Config
5+
import boto3 # type: ignore
6+
from botocore.config import Config # type: ignore
77

88
from aws_lambda_powertools.utilities.idempotency import BasePersistenceLayer
99
from aws_lambda_powertools.utilities.idempotency.exceptions import (

aws_lambda_powertools/utilities/parameters/appconfig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from typing import Any, Dict, Optional, Union
88
from uuid import uuid4
99

10-
import boto3
11-
from botocore.config import Config
10+
import boto3 # type: ignore
11+
from botocore.config import Config # type: ignore
1212

1313
from ...shared import constants
1414
from ...shared.functions import resolve_env_var_choice

aws_lambda_powertools/utilities/parameters/dynamodb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from typing import Any, Dict, Optional
77

8-
import boto3
9-
from boto3.dynamodb.conditions import Key
10-
from botocore.config import Config
8+
import boto3 # type: ignore
9+
from boto3.dynamodb.conditions import Key # type: ignore
10+
from botocore.config import Config # type: ignore
1111

1212
from .base import BaseProvider
1313

aws_lambda_powertools/utilities/parameters/secrets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from typing import Any, Dict, Optional, Union
77

8-
import boto3
9-
from botocore.config import Config
8+
import boto3 # type: ignore
9+
from botocore.config import Config # type: ignore
1010

1111
from .base import DEFAULT_PROVIDERS, BaseProvider
1212

aws_lambda_powertools/utilities/parameters/ssm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from typing import Any, Dict, Optional, Union
77

8-
import boto3
9-
from botocore.config import Config
8+
import boto3 # type: ignore
9+
from botocore.config import Config # type: ignore
1010

1111
from .base import DEFAULT_MAX_AGE_SECS, DEFAULT_PROVIDERS, BaseProvider
1212

aws_lambda_powertools/utilities/validation/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
2-
from typing import Any, Dict, Optional
2+
from typing import Any, Dict, Optional, Union
33

4-
import fastjsonschema
5-
import jmespath
6-
from jmespath.exceptions import LexerError
4+
import fastjsonschema # type: ignore
5+
import jmespath # type: ignore
6+
from jmespath.exceptions import LexerError # type: ignore
77

88
from aws_lambda_powertools.shared.jmespath_functions import PowertoolsFunctions
99

@@ -12,7 +12,7 @@
1212
logger = logging.getLogger(__name__)
1313

1414

15-
def validate_data_against_schema(data: Dict, schema: Dict, formats: Optional[Dict] = None):
15+
def validate_data_against_schema(data: Union[Dict, str], schema: Dict, formats: Optional[Dict] = None):
1616
"""Validate dict data against given JSON Schema
1717
1818
Parameters
@@ -41,7 +41,7 @@ def validate_data_against_schema(data: Dict, schema: Dict, formats: Optional[Dic
4141
raise SchemaValidationError(message)
4242

4343

44-
def unwrap_event_from_envelope(data: Dict, envelope: str, jmespath_options: Optional[Dict]) -> Any:
44+
def unwrap_event_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any:
4545
"""Searches data using JMESPath expression
4646
4747
Parameters

poetry.lock

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ flake8-bugbear = "^21.3.2"
5252
mkdocs-material = "^7.1.9"
5353
mkdocs-git-revision-date-plugin = "^0.3.1"
5454
mike = "^0.6.0"
55+
mypy = "^0.910"
5556

5657

5758
[tool.poetry.extras]

0 commit comments

Comments
 (0)