Skip to content

Commit b868e1f

Browse files
committed
fix: code inspect issues
1 parent f0ff926 commit b868e1f

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
lines changed

aws_lambda_powertools/utilities/parser/envelopes/base.py

Lines changed: 2 additions & 2 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
3+
from typing import Any, Dict, Union
44

55
from pydantic import BaseModel, ValidationError
66

@@ -11,7 +11,7 @@
1111

1212
class BaseEnvelope(ABC):
1313
@staticmethod
14-
def _parse(event: Dict[str, Any], schema: BaseModel) -> Any:
14+
def _parse(event: Union[Dict[str, Any], str], schema: BaseModel) -> Any:
1515
if event is None:
1616
logger.debug("Skipping parsing as event is None")
1717
return event

aws_lambda_powertools/utilities/parser/envelopes/dynamodb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ def parse(self, event: Dict[str, Any], schema: BaseModel) -> List[Dict[Literal["
5151
"OldImage": self._parse(record.dynamodb.OldImage, schema),
5252
}
5353
)
54+
# noinspection PyTypeChecker
5455
return output

aws_lambda_powertools/utilities/parser/envelopes/sqs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ def parse(self, event: Dict[str, Any], schema: Union[BaseModel, str]) -> List[Un
4444
parsed_envelope = SqsSchema(**event)
4545
except (ValidationError, TypeError) as e:
4646
raise SchemaValidationError("SQS input doesn't conform with schema") from e
47-
output = [self._parse(record.body, schema) for record in parsed_envelope.Records]
47+
output = []
48+
for record in parsed_envelope.Records:
49+
output.append(self._parse(record.body, schema))
4850
return output

aws_lambda_powertools/utilities/parser/parser.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,43 @@ def parser(
1919
schema: BaseModel,
2020
envelope: Optional[BaseEnvelope] = None,
2121
) -> Any:
22+
# noinspection SpellCheckingInspection,SpellCheckingInspection
2223
"""Decorator to conduct advanced parsing & validation for lambda handlers events
2324
24-
As Lambda follows (event, context) signature we can remove some of the boilerplate
25-
and also capture any exception any Lambda function throws as metadata.
26-
event will be the parsed and passed as a BaseModel pydantic class of the input type "schema"
27-
to the lambda handler.
28-
event will be extracted from the envelope in case envelope is not None.
29-
In case envelope is None, the complete event is parsed to match the schema parameter BaseModel definition.
30-
In case envelope is not None, first the event is parsed as the envelope's schema definition, and the user
31-
message is extracted and parsed again as the schema parameter's definition.
25+
As Lambda follows (event, context) signature we can remove some of the boilerplate
26+
and also capture any exception any Lambda function throws as metadata.
27+
event will be the parsed and passed as a BaseModel pydantic class of the input type "schema"
28+
to the lambda handler.
29+
event will be extracted from the envelope in case envelope is not None.
30+
In case envelope is None, the complete event is parsed to match the schema parameter BaseModel definition.
31+
In case envelope is not None, first the event is parsed as the envelope's schema definition, and the user
32+
message is extracted and parsed again as the schema parameter's definition.
3233
33-
Example
34-
-------
35-
**Lambda function using validation decorator**
34+
Example
35+
-------
36+
**Lambda function using validation decorator**
3637
37-
@parser(schema=MyBusiness, envelope=envelopes.EVENTBRIDGE)
38-
def handler(event: MyBusiness , context: LambdaContext):
39-
...
38+
@parser(schema=MyBusiness, envelope=envelopes.EVENTBRIDGE)
39+
def handler(event: MyBusiness , context: LambdaContext):
40+
...
4041
41-
Parameters
42-
----------
43-
handler: input for lambda_handler_decorator, wraps the handler lambda
44-
event: AWS event dictionary
45-
context: AWS lambda context
46-
schema: pydantic BaseModel class. This is the user data schema that will replace the event.
47-
event parameter will be parsed and a new schema object will be created from it.
48-
envelope: what envelope to extract the schema from, can be any AWS service that is currently
49-
supported in the envelopes module. Can be None.
42+
Parameters
43+
----------
44+
handler: input for lambda_handler_decorator, wraps the handler lambda
45+
event: AWS event dictionary
46+
context: AWS lambda context
47+
schema: pydantic BaseModel class. This is the user data schema that will replace the event.
48+
event parameter will be parsed and a new schema object will be created from it.
49+
envelope: what envelope to extract the schema from, can be any AWS service that is currently
50+
supported in the envelopes module. Can be None.
5051
51-
Raises
52-
------
53-
SchemaValidationError
54-
When input event doesn't conform with schema provided
55-
InvalidSchemaTypeError
56-
When schema given does not implement BaseModel
57-
"""
52+
Raises
53+
------
54+
SchemaValidationError
55+
When input event doesn't conform with schema provided
56+
InvalidSchemaTypeError
57+
When schema given does not implement BaseModel
58+
"""
5859
if envelope is None:
5960
try:
6061
logger.debug("Parsing and validating event schema; no envelope used")

0 commit comments

Comments
 (0)