Closed
Description
The model
argument of BaseEnvelope
and all its subclasses should be of type Type[Model]
, not just Model
.
The same issue affects parse
.
Expected Behavior
Parsing an event dict using one of the envelope classes expects a BaseModel
class as a parameter and returns an instance of that class. The type signature should match.
Current Behavior
mypy complains with the error
Argument 2 to "parse" of "SqsEnvelope" has incompatible type "Type[Record]"; expected "Record"
Possible Solution
The type signature of the model argument should be changed to Type[Model]
.
Steps to Reproduce (for bugs)
# main.py
from typing import Dict, List, Optional
from aws_lambda_powertools.utilities.parser import envelopes, parse
from pydantic import BaseModel
class Record(BaseModel):
id: str
envelope = envelopes.SqsEnvelope()
records: List[Optional[Record]] = envelope.parse({}, Record)
records2: List[Optional[Record]] = parse({}, model=Record, envelope=envelope)
mypy main.py
main.py:11: error: Argument 2 to "parse" of "SqsEnvelope" has incompatible type "Type[Record]"; expected "Record"
main.py:13: error: Value of type variable "Model" of "parse" cannot be "Type[Record]"
main.py:13: error: Incompatible types in assignment (expression has type "Type[Record]", variable has type "List[Optional[Record]]")
Found 3 errors in 1 file (checked 1 source file)
Environment
- Python 3.8.5
- aws-lambda-powertools==1.10.2
- mypy==0.800
- pydantic==1.7.3
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Triage