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 type annotations in responses.py #1711

Merged
merged 2 commits into from Jun 28, 2022
Merged

Conversation

adriangb
Copy link
Sponsor Member

@adriangb adriangb commented Jun 28, 2022

Adding/fixing a couple minor typing nits in responses.py

@@ -112,7 +112,7 @@ def set_cookie(
httponly: bool = False,
samesite: typing.Optional[Literal["lax", "strict", "none"]] = "lax",
) -> None:
cookie: http.cookies.BaseCookie = http.cookies.SimpleCookie()
cookie: "http.cookies.BaseCookie[str]" = http.cookies.SimpleCookie()
Copy link
Sponsor Member

@Kludex Kludex Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this correct? I can see it fixes the issue with pyright, but I don't understand how a single argument works, as BaseCookie is a dict 🤔

Copy link
Sponsor Member Author

@adriangb adriangb Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you asking why str is the correct type? Both key and value are str (from the function signature) and str made type checker happy so pretty sure str is correct.

Copy link
Sponsor Member

@Kludex Kludex Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed on our conversation outside GitHub... It's because of the definition on typeshed: https://github.com/python/typeshed/blob/544c7c963333a4a415b951f13a6a6bbec2421161/stdlib/http/cookies.pyi#L54

Thanks @adriangb 😗

Kludex
Kludex approved these changes Jun 28, 2022
@adriangb adriangb merged commit c4e583b into encode:master Jun 28, 2022
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants