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

Wrong type signature on parser envelopes #285

Closed
zroger opened this issue Feb 6, 2021 · 2 comments
Closed

Wrong type signature on parser envelopes #285

zroger opened this issue Feb 6, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@zroger
Copy link

zroger commented Feb 6, 2021

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
@zroger zroger added bug Something isn't working triage Pending triage from maintainers labels Feb 6, 2021
@heitorlessa
Copy link
Contributor

heitorlessa commented Feb 9, 2021

@nmoutschen Could you please check this before you release a patch version for Tracer? This seems like a super quick fix to help MyPy customers.

Related issue with much bigger scope to support MyPy: #221

@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 12, 2021
@heitorlessa
Copy link
Contributor

This is now available in 1.10.3 - Closing it. Thank you for reporting another one @zroger, and for the fix @nmoutschen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants