refactor(internal): extract body-cap module out of client.py#97
Merged
Conversation
…om client.py Move the max_response_body_bytes enforcement code (validation, capped sync/async reads, and their helpers) into a new _internal/body_cap.py, and move the _httpx2_exception_mapper(/_sync) context managers into the existing _internal/exception_mapping.py alongside map_httpx2_exception. Pure refactor: no behavior change, only import paths move. client.py drops ~160 lines of self-contained logic it never needed class access to. Rename tests/test_capped_read(_props).py to tests/test_body_cap(_props).py to match, and relocate test_parse_content_length out of test_client_stream.py into the renamed test_body_cap.py.
errors.md and client.md said the httpx2-exception-mapping table "lives at the terminal in client.py" — true before this branch, but the body-cap extraction moved the last mapping code out of client.py entirely, into _internal/exception_mapping.py. Distinguish where the table lives from where it fires.
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
max_response_body_bytesbody-capping subsystem out ofclient.pyinto a new_internal/body_cap.py, and folds the two httpx2-exception-mapper context managers into the existing_internal/exception_mapping.py— pure move, no behavior change.client.pyshrinks by ~200 lines to a 3-name import for body-cap plus two for exception mapping;_build_default_decodersstays put perarchitecture/decoders.md.architecture/errors.md/client.md("error-mapping table lives at the terminal in client.py") that this branch makes flatly false.Design:
planning/changes/2026-07-13.01-body-cap-module-extraction.mdTest plan
just test— 766 passed, 100% coveragejust lint-ci— ruff format/check,ty check, planning validator all cleanjust docs-build— mkdocs--strictclean