Skip to content
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

fix: fix typing hit for envelope parse model #286

Merged
merged 1 commit into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
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
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