Skip to content

chore(mypy): add mypy support to makefile #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ release: pr
changelog:
@echo "[+] Pre-generating CHANGELOG for tag: $$(git describe --abbrev=0 --tag)"
docker run -v "${PWD}":/workdir quay.io/git-chglog/git-chglog $$(git describe --abbrev=0 --tag).. > TMP_CHANGELOG.md

mypy:
poetry run mypy aws_lambda_powertools
12 changes: 6 additions & 6 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import os
import random
import sys
from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union
from typing import IO, Any, Callable, Dict, Iterable, Optional, TypeVar, Union

import jmespath
import jmespath # type: ignore

from ..shared import constants
from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
Expand Down Expand Up @@ -171,7 +171,7 @@ def __init__(
level: Union[str, int] = None,
child: bool = False,
sampling_rate: float = None,
stream: sys.stdout = None,
stream: IO[str] = None,
logger_formatter: Optional[PowertoolsFormatter] = None,
logger_handler: Optional[logging.Handler] = None,
**kwargs,
Expand Down Expand Up @@ -363,7 +363,7 @@ def registered_handler(self) -> logging.Handler:
@property
def registered_formatter(self) -> Optional[PowertoolsFormatter]:
"""Convenience property to access logger formatter"""
return self.registered_handler.formatter
return self.registered_handler.formatter # type: ignore

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

def set_correlation_id(self, value: str):
Expand Down Expand Up @@ -421,7 +421,7 @@ def _get_caller_filename():


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

Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/shared/jmespath_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import gzip
import json

import jmespath
import jmespath # type: ignore


class PowertoolsFunctions(jmespath.functions.Functions):
Expand Down
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/batch/sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import sys
from typing import Callable, Dict, List, Optional, Tuple

import boto3
from botocore.config import Config
import boto3 # type: ignore
from botocore.config import Config # type: ignore

from ...middleware_factory import lambda_handler_decorator
from .base import BasePartialProcessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Dict, List, Optional
from urllib.parse import unquote_plus

import boto3
import boto3 # type: ignore

from aws_lambda_powertools.utilities.data_classes.common import DictWrapper

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from types import MappingProxyType
from typing import Any, Dict, Optional

import jmespath
import jmespath # type: ignore

from aws_lambda_powertools.shared.cache_dict import LRUDict
from aws_lambda_powertools.shared.jmespath_functions import PowertoolsFunctions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import logging
from typing import Any, Dict, Optional

import boto3
from botocore.config import Config
import boto3 # type: ignore
from botocore.config import Config # type: ignore

from aws_lambda_powertools.utilities.idempotency import BasePersistenceLayer
from aws_lambda_powertools.utilities.idempotency.exceptions import (
Expand Down
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/parameters/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing import Any, Dict, Optional, Union
from uuid import uuid4

import boto3
from botocore.config import Config
import boto3 # type: ignore
from botocore.config import Config # type: ignore

from ...shared import constants
from ...shared.functions import resolve_env_var_choice
Expand Down
6 changes: 3 additions & 3 deletions aws_lambda_powertools/utilities/parameters/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from typing import Any, Dict, Optional

import boto3
from boto3.dynamodb.conditions import Key
from botocore.config import Config
import boto3 # type: ignore
from boto3.dynamodb.conditions import Key # type: ignore
from botocore.config import Config # type: ignore

from .base import BaseProvider

Expand Down
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/parameters/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from typing import Any, Dict, Optional, Union

import boto3
from botocore.config import Config
import boto3 # type: ignore
from botocore.config import Config # type: ignore

from .base import DEFAULT_PROVIDERS, BaseProvider

Expand Down
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/parameters/ssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from typing import Any, Dict, Optional, Union

import boto3
from botocore.config import Config
import boto3 # type: ignore
from botocore.config import Config # type: ignore

from .base import DEFAULT_MAX_AGE_SECS, DEFAULT_PROVIDERS, BaseProvider

Expand Down
12 changes: 6 additions & 6 deletions aws_lambda_powertools/utilities/validation/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, Union

import fastjsonschema
import jmespath
from jmespath.exceptions import LexerError
import fastjsonschema # type: ignore
import jmespath # type: ignore
from jmespath.exceptions import LexerError # type: ignore

from aws_lambda_powertools.shared.jmespath_functions import PowertoolsFunctions

Expand All @@ -12,7 +12,7 @@
logger = logging.getLogger(__name__)


def validate_data_against_schema(data: Dict, schema: Dict, formats: Optional[Dict] = None):
def validate_data_against_schema(data: Union[Dict, str], schema: Dict, formats: Optional[Dict] = None):
"""Validate dict data against given JSON Schema

Parameters
Expand Down Expand Up @@ -41,7 +41,7 @@ def validate_data_against_schema(data: Dict, schema: Dict, formats: Optional[Dic
raise SchemaValidationError(message)


def unwrap_event_from_envelope(data: Dict, envelope: str, jmespath_options: Optional[Dict]) -> Any:
def unwrap_event_from_envelope(data: Union[Dict, str], envelope: str, jmespath_options: Optional[Dict]) -> Any:
"""Searches data using JMESPath expression

Parameters
Expand Down
46 changes: 44 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ flake8-bugbear = "^21.3.2"
mkdocs-material = "^7.1.9"
mkdocs-git-revision-date-plugin = "^0.3.1"
mike = "^0.6.0"
mypy = "^0.910"


[tool.poetry.extras]
Expand Down