Skip to content

Static typing: headers in Response should be Mapping instead of Dict #3743

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

Closed
tonnico opened this issue Feb 9, 2024 · 3 comments
Closed
Assignees
Labels
typing Static typing definition related issues (mypy, pyright, etc.)

Comments

@tonnico
Copy link
Contributor

tonnico commented Feb 9, 2024

Static type checker used

mypy (project's standard)

AWS Lambda function runtime

3.12

Powertools for AWS Lambda (Python) version

latest

Static type checker info

error: Argument "headers" to "Response" has incompatible type "dict[str, str]"; expected
"dict[str, str | list[str]] | None"  [arg-type]
            headers=headers,
                    ^~~~~~~
note: "Dict" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
note: Consider using "Mapping" instead, which is covariant in the value type

Code snippet

headers = {"str": "str"}
Response(200, headers=headers)

Possible Solution

Instead of Dict[str, Union[str, List[str]] use Mapping[str, Union[str, List[str]].
E.g. https://stackoverflow.com/a/73603324/6621062

@tonnico tonnico added triage Pending triage from maintainers typing Static typing definition related issues (mypy, pyright, etc.) labels Feb 9, 2024
@heitorlessa heitorlessa moved this from Triage to Working on it in Powertools for AWS Lambda (Python) Feb 9, 2024
@heitorlessa heitorlessa self-assigned this Feb 9, 2024
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Feb 9, 2024
@heitorlessa
Copy link
Contributor

thanks a lot @wurstnase for taking the time, truly ;) Merging shortly so it's part of today's release!!

@heitorlessa
Copy link
Contributor

Merged, should be available to everyone in the next few hours on PyPi and Lambda Layers.

Huge welcome to the Powertools for AWS community @wurstnase <3

@heitorlessa heitorlessa moved this from Working on it to Coming soon in Powertools for AWS Lambda (Python) Feb 9, 2024
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Feb 9, 2024
Copy link
Contributor

github-actions bot commented Feb 9, 2024

This is now released under 2.33.1 version!

@github-actions github-actions bot closed this as completed Feb 9, 2024
@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 9, 2024
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Static typing definition related issues (mypy, pyright, etc.)
Projects
Status: Shipped
Development

No branches or pull requests

2 participants