Skip to content

Commit

Permalink
fix: sfix typing hit for envelope parse model (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmoutschen authored Feb 12, 2021
1 parent 7b23b5b commit bf66299
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions aws_lambda_powertools/utilities/parser/envelopes/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from abc import ABC, abstractmethod
from typing import Any, Dict, Optional, TypeVar, Union
from typing import Any, Dict, Optional, Type, TypeVar, Union

from ..types import Model

Expand All @@ -11,14 +11,14 @@ class BaseEnvelope(ABC):
"""ABC implementation for creating a supported Envelope"""

@staticmethod
def _parse(data: Optional[Union[Dict[str, Any], Any]], model: Model) -> Union[Model, None]:
def _parse(data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> Union[Model, None]:
"""Parses envelope data against model provided
Parameters
----------
data : Dict
Data to be parsed and validated
model : Model
model : Type[Model]
Data model to parse and validate data against
Returns
Expand All @@ -38,7 +38,7 @@ def _parse(data: Optional[Union[Dict[str, Any], Any]], model: Model) -> Union[Mo
return model.parse_obj(data)

@abstractmethod
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model):
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]):
"""Implementation to parse data against envelope model, then against the data model
NOTE: Call `_parse` method to fully parse data with model provided.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union

from ..models import CloudWatchLogsModel
from ..types import Model
Expand All @@ -18,14 +18,14 @@ class CloudWatchLogsEnvelope(BaseEnvelope):
Note: The record will be parsed the same way so if model is str
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Optional[Model]]:
"""Parses records found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down
6 changes: 3 additions & 3 deletions aws_lambda_powertools/utilities/parser/envelopes/dynamodb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union

from ..models import DynamoDBStreamModel
from ..types import Model
Expand All @@ -15,14 +15,14 @@ class DynamoDBStreamEnvelope(BaseEnvelope):
length of the list is the record's amount in the original event.
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Dict[str, Optional[Model]]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Dict[str, Optional[Model]]]:
"""Parses DynamoDB Stream records found in either NewImage and OldImage with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Optional, Type, Union

from ..models import EventBridgeModel
from ..types import Model
Expand All @@ -11,14 +11,14 @@
class EventBridgeEnvelope(BaseEnvelope):
"""EventBridge envelope to extract data within detail key"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> Optional[Model]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> Optional[Model]:
"""Parses data found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down
6 changes: 3 additions & 3 deletions aws_lambda_powertools/utilities/parser/envelopes/kinesis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union

from ..models import KinesisDataStreamModel
from ..types import Model
Expand All @@ -19,14 +19,14 @@ class KinesisDataStreamEnvelope(BaseEnvelope):
all items in the list will be parsed as str and npt as JSON (and vice versa)
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Optional[Model]]:
"""Parses records found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down
12 changes: 6 additions & 6 deletions aws_lambda_powertools/utilities/parser/envelopes/sns.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union

from ..models import SnsModel, SnsNotificationModel, SqsModel
from ..types import Model
Expand All @@ -16,16 +16,16 @@ class SnsEnvelope(BaseEnvelope):
Note: Records will be parsed the same way so if model is str,
all items in the list will be parsed as str and npt as JSON (and vice versa)
"""
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Optional[Model]]:
"""Parses records found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand All @@ -50,14 +50,14 @@ class SnsSqsEnvelope(BaseEnvelope):
3. Finally, parse provided model against payload extracted
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Optional[Model]]:
"""Parses records found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down
6 changes: 3 additions & 3 deletions aws_lambda_powertools/utilities/parser/envelopes/sqs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Type, Union

from ..models import SqsModel
from ..types import Model
Expand All @@ -18,14 +18,14 @@ class SqsEnvelope(BaseEnvelope):
all items in the list will be parsed as str and npt as JSON (and vice versa)
"""

def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Model) -> List[Optional[Model]]:
def parse(self, data: Optional[Union[Dict[str, Any], Any]], model: Type[Model]) -> List[Optional[Model]]:
"""Parses records found with model provided
Parameters
----------
data : Dict
Lambda event to be parsed
model : Model
model : Type[Model]
Data model provided to parse after extracting data using envelope
Returns
Expand Down

0 comments on commit bf66299

Please sign in to comment.