Skip to content

Commit 1b5d045

Browse files
fix: small changes
1 parent 027e8d7 commit 1b5d045

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

aws_lambda_powertools/utilities/parser/envelopes/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ def _parse(data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
4444
return _parse_and_validate_event(data=data, adapter=adapter)
4545

4646
@abstractmethod
47-
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | list[T | None] | None:
47+
def parse(
48+
self,
49+
data: dict[str, Any] | Any | None,
50+
model: type[T],
51+
) -> T | list[T | None] | list[dict[str, T | None]] | None:
4852
"""Implementation to parse data against envelope model, then against the data model
4953
5054
NOTE: Call `_parse` method to fully parse data with model provided.

aws_lambda_powertools/utilities/parser/parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ def parse(event: dict[str, Any], model: type[T]) -> T: ... # pragma: no cover
124124

125125

126126
@overload
127-
def parse(event: dict[str, Any], model: type[T], envelope: type[Envelope]) -> T | list[T | None] | None: ... # pragma: no cover
127+
def parse( # pragma: no cover
128+
event: dict[str, Any],
129+
model: type[T],
130+
envelope: type[Envelope],
131+
) -> T | list[T | None] | list[dict[str, T | None]] | None: ...
128132

129133

130134
def parse(event: dict[str, Any], model: type[T], envelope: type[Envelope] | None = None):

examples/parser/src/bring_your_own_envelope.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
from __future__ import annotations
2+
13
import json
2-
from typing import Any, Dict, Optional, Type, TypeVar, Union
4+
from typing import Any, TypeVar
35

46
from pydantic import BaseModel
57

68
from aws_lambda_powertools.utilities.parser import BaseEnvelope, event_parser
79
from aws_lambda_powertools.utilities.parser.models import EventBridgeModel
810
from aws_lambda_powertools.utilities.typing import LambdaContext
911

10-
Model = TypeVar("Model", bound=BaseModel)
12+
T = TypeVar("T")
1113

1214

1315
class EventBridgeEnvelope(BaseEnvelope):
14-
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> Optional[Model]:
16+
def parse(self, data: dict[str, Any] | Any | None, model: type[T]) -> T | None:
1517
if data is None:
1618
return None
1719

0 commit comments

Comments
 (0)