refactor(errors): collapse per-exception reconstruct/reduce boilerplate#99
Merged
Conversation
…te with _KeywordReduceMixin Replace six hand-repeated _reconstruct_X functions and __reduce__ methods with a single _KeywordReduceMixin that pickles via self.__dict__. Updates architecture/errors.md with the pickling invariant. Pure refactor, no behavior change; all 775 tests pass with 100% coverage. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Final review caught that the docstring and architecture/errors.md both described the wrong failure mode: an extra attribute beyond __init__'s keyword params raises TypeError on unpickle (loud), not a silent drop. The silent-drop case is the opposite: a keyword param __init__ forgets to assign to self, which reverts to its default on unpickle if it has one.
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
_reconstruct_X+__reduce__pairs inerrors.py(RetryBudgetExhaustedError,BulkheadFullError,CircuitOpenError,DecodeError,MissingDecoderError,ResponseTooLargeError) into one shared_KeywordReduceMixin+_reconstruct_kwonlyfunction.ClientErroritself — verified that would silently break pickling forTransportError/NetworkError/TimeoutError, which store their message inself.args, notself.__dict__.StatusError's own, separate, already-shared reduce mechanism is untouched.architecture/errors.mdrecording the mixin's precondition, with wording corrected during final review (an extra attribute raisesTypeErrorloudly on unpickle; a silent drop happens only when a keyword param with a default is never assigned toself).Design:
planning/changes/2026-07-13.03-errors-keyword-reduce-mixin.mdTest plan
just test— 775 passed, 100% coveragejust lint-ci— ruff format/check,ty check, planning validator all cleanjust docs-build— mkdocs--strictclean