Skip to content

Make client.cookies setter expect a Cookies instance - #678

Closed
florimondmanca wants to merge 1 commit into
masterfrom
tweak-cookies-types
Closed

florimondmanca wants to merge 1 commit into
masterfrom
tweak-cookies-types

Conversation

@florimondmanca

@florimondmanca florimondmanca commented Dec 21, 2019 •

Copy link
Copy Markdown
Contributor

Prompted by #677 (comment)

@tomchristie IMO the only thing that does look odd (at least from a typing perspective) is the setter magic, so this PR focuses on that. In particular, not sure we really want to get rid of CookieTypes and change the cookies parameters to prevent using the convenience dict/CookieJar types.

@florimondmanca florimondmanca added the refactor Issues and PRs related to code refactoring label Dec 21, 2019
Comment thread httpx/client.py
def cookies(self, cookies: CookieTypes) -> None:
self._cookies = Cookies(cookies)
def cookies(self, cookies: Cookies) -> None:
self._cookies = cookies

@florimondmanca florimondmanca Dec 21, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@tomchristie Would we want to add an assert or any kind of runtime type check here? I'm not sure it's really needed.

Also, this change makes the cookies property equivalent to a simple variable, so we might as well switch it to just that — a plain and public .cookies variable?

@florimondmanca
florimondmanca requested a review from a team December 21, 2019 23:11
@lovelydinosaur

Copy link
Copy Markdown
Member

I think we should probably only do this if we're also doing the same for Headers and Params.
It's very possibly a good thing to do in all cases, but perhaps let's defer that decision for now, and allow the type: ignore on https://github.com/encode/httpx/pull/677/files#diff-2aeaac4c23c1f6bf49dfbd99885a3aa7L108 for the moment.

@florimondmanca

Copy link
Copy Markdown
Contributor Author

Closing this one for now to be addressed later with a pass on Headers and Params, then.

@florimondmanca
florimondmanca deleted the tweak-cookies-types branch December 23, 2019 09:51
@lovelydinosaur lovelydinosaur mentioned this pull request Jan 6, 2020
8 of 10 tasks
Kludex referenced this pull request in pydantic/httpx2 May 11, 2026
Preserves the exception chain instead of displaying "During handling of the above exception, another exception occurred" in the traceback

Co-authored-by: Tom Christie <tom@tomchristie.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Issues and PRs related to code refactoring

Development

Successfully merging this pull request may close these issues.

2 participants