Skip to content

refactor(errors): collapse per-exception reconstruct/reduce boilerplate#99

Merged
lesnik512 merged 3 commits into
mainfrom
worktree-errors-keyword-reduce-mixin
Jul 13, 2026
Merged

refactor(errors): collapse per-exception reconstruct/reduce boilerplate#99
lesnik512 merged 3 commits into
mainfrom
worktree-errors-keyword-reduce-mixin

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

  • Collapses 6 hand-duplicated _reconstruct_X + __reduce__ pairs in errors.py (RetryBudgetExhaustedError, BulkheadFullError, CircuitOpenError, DecodeError, MissingDecoderError, ResponseTooLargeError) into one shared _KeywordReduceMixin + _reconstruct_kwonly function.
  • Deliberately NOT applied to ClientError itself — verified that would silently break pickling for TransportError/NetworkError/TimeoutError, which store their message in self.args, not self.__dict__.
  • StatusError's own, separate, already-shared reduce mechanism is untouched.
  • Adds one doc paragraph to architecture/errors.md recording the mixin's precondition, with wording corrected during final review (an extra attribute raises TypeError loudly on unpickle; a silent drop happens only when a keyword param with a default is never assigned to self).
  • No test changes — the 6 existing pickle-round-trip tests already exercise the shared mixin directly and verify unpickling, not just pickling.

Design: planning/changes/2026-07-13.03-errors-keyword-reduce-mixin.md

Test plan

  • just test — 775 passed, 100% coverage
  • just lint-ci — ruff format/check, ty check, planning validator all clean
  • just docs-build — mkdocs --strict clean
  • Task-scoped review (spec + quality): Approved
  • Final whole-branch review: Ready to merge = Yes, no Critical/Important findings

lesnik512 and others added 3 commits July 13, 2026 14:46
…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.
@lesnik512 lesnik512 merged commit 0b349b2 into main Jul 13, 2026
6 checks passed
@lesnik512 lesnik512 deleted the worktree-errors-keyword-reduce-mixin branch July 13, 2026 12:15
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.

1 participant