Skip to content

Commit 33fec71

Browse files
committed
improv: address Koudai's PR feedback on mypy
1 parent ffbde1d commit 33fec71

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

aws_lambda_powertools/utilities/parser/envelopes/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from abc import ABC, abstractmethod
3-
from typing import Any, Dict, TypeVar, Union
3+
from typing import Any, Dict, Optional, TypeVar, Union
44

55
from ..types import Model
66

@@ -11,7 +11,7 @@ class BaseEnvelope(ABC):
1111
"""ABC implementation for creating a supported Envelope"""
1212

1313
@staticmethod
14-
def _parse(data: Union[Dict[str, Any], str], model: Model) -> Union[Model, None]:
14+
def _parse(data: Optional[Union[Dict[str, Any], Any]], model: Model) -> Union[Model, None]:
1515
"""Parses envelope data against model provided
1616
1717
Parameters
@@ -38,7 +38,7 @@ def _parse(data: Union[Dict[str, Any], str], model: Model) -> Union[Model, None]
3838
return model.parse_obj(data)
3939

4040
@abstractmethod
41-
def parse(self, data: Dict[str, Any], model: Model):
41+
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model):
4242
"""Implementation to parse data against envelope model, then against the data model
4343
4444
NOTE: Call `_parse` method to fully parse data with model provided.

aws_lambda_powertools/utilities/parser/envelopes/dynamodb.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import logging
2-
from typing import Any, Dict, List
3-
4-
from typing_extensions import Literal
2+
from typing import Any, Dict, List, Optional, Union
53

64
from ..models import DynamoDBStreamModel
75
from ..types import Model
@@ -17,7 +15,7 @@ class DynamoDBStreamEnvelope(BaseEnvelope):
1715
length of the list is the record's amount in the original event.
1816
"""
1917

20-
def parse(self, data: Dict[str, Any], model: Model) -> List[Dict[Literal["NewImage", "OldImage"], Model]]:
18+
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Dict[str, Optional[Model]]]:
2119
"""Parses DynamoDB Stream records found in either NewImage and OldImage with model provided
2220
2321
Parameters
@@ -30,7 +28,7 @@ def parse(self, data: Dict[str, Any], model: Model) -> List[Dict[Literal["NewIma
3028
Returns
3129
-------
3230
List
33-
List of records parsed with model provided
31+
List of dictionaries with NewImage and OldImage records parsed with model provided
3432
"""
3533
logger.debug(f"Parsing incoming data with DynamoDB Stream model {DynamoDBStreamModel}")
3634
parsed_envelope = DynamoDBStreamModel.parse_obj(data)
@@ -43,5 +41,4 @@ def parse(self, data: Dict[str, Any], model: Model) -> List[Dict[Literal["NewIma
4341
"OldImage": self._parse(data=record.dynamodb.OldImage, model=model),
4442
}
4543
)
46-
# noinspection PyTypeChecker
4744
return output

aws_lambda_powertools/utilities/parser/envelopes/event_bridge.py

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

44
from ..models import EventBridgeModel
55
from ..types import Model
@@ -11,7 +11,7 @@
1111
class EventBridgeEnvelope(BaseEnvelope):
1212
"""EventBridge envelope to extract data within detail key"""
1313

14-
def parse(self, data: Dict[str, Any], model: Model) -> Model:
14+
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> Optional[Model]:
1515
"""Parses data found with model provided
1616
1717
Parameters

aws_lambda_powertools/utilities/parser/envelopes/sqs.py

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

44
from ..models import SqsModel
55
from ..types import Model
@@ -18,7 +18,7 @@ class SqsEnvelope(BaseEnvelope):
1818
all items in the list will be parsed as str and npt as JSON (and vice versa)
1919
"""
2020

21-
def parse(self, data: Dict[str, Any], model: Model) -> List[Model]:
21+
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
2222
"""Parses records found with model provided
2323
2424
Parameters

aws_lambda_powertools/utilities/parser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
@lambda_handler_decorator
1414
def event_parser(
15-
handler: Callable[[Dict, Any], Any],
15+
handler: Callable[[Any, LambdaContext], Any],
1616
event: Dict[str, Any],
1717
context: LambdaContext,
1818
model: Model,

0 commit comments

Comments
 (0)