Avoid expensive cookie truthiness checks#953
Open
Sean-Kenneth-Doherty wants to merge 2 commits into
Open
Conversation
f41df8e to
d100c10
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
d100c10 to
cb1bf24
Compare
Author
|
Local validation on updated head
I also replaced the custom-jar fallback test with a real |
Author
|
Follow-up coverage fix is on Local validation under Python 3.11:
Hosted checks are now green for Python 3.10, 3.11, 3.12, 3.13, 3.14, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #783 by avoiding expensive cookie truthiness checks in the request cookie merge path.
Cookies.__bool__use theCookieJarinternal cookie store when available instead of iterating throughdeepvalues_cookiesstoreRoot Cause
CookieJar.__iter__walks the nested cookie store viahttp.cookiejar.deepvalues. BothBaseClient._merge_cookies()and request construction can hit cookie truthiness checks on hot paths, so checking for cookie presence should avoid that traversal when the jar exposes its internal store.Validation
uv run --frozen python -m pytest -q tests/httpx2/models/test_cookies.py::test_cookies_bool_does_not_iterate_cookie_jar tests/httpx2/models/test_cookies.py::test_cookies_bool_iterates_custom_cookie_jar_without_cookie_store tests/httpx2/client/test_cookies.py::test_set_per_request_cookie_merges_with_client_cookiesuv run --frozen python -m pytest -q tests/httpx2/models/test_cookies.py tests/httpx2/client/test_cookies.pyscripts/checkuv run --frozen python -m pytest -q tests/httpx2(1422 passed, 1 skipped)python -m compileall -q src/httpx2/httpx2/_client.py src/httpx2/httpx2/_models.py tests/httpx2/client/test_cookies.py tests/httpx2/models/test_cookies.pygit diff --check origin/main...HEAD && git diff --checkUpstream CI is also green for Python 3.10 through 3.14, the check job, and security analysis.
Microbenchmark on this branch, 1,000 cookies and 200,000 truthiness checks: