Skip to content

Refactor timeout and body handling to use match statements#3112

Merged
adamtheturtle merged 3 commits intomainfrom
adamtheturtle/match-timeout-body
Apr 15, 2026
Merged

Refactor timeout and body handling to use match statements#3112
adamtheturtle merged 3 commits intomainfrom
adamtheturtle/match-timeout-body

Conversation

@adamtheturtle
Copy link
Copy Markdown
Member

@adamtheturtle adamtheturtle commented Apr 15, 2026

Summary

  • Replace isinstance chains with match/case for timeout normalization and request body → bytes conversion in _wrap_callback

Closes #3110

Test plan

  • All pre-commit hooks pass
  • Existing tests pass (no behavioral changes)

🤖 Generated with Claude Code


Note

Low Risk
Pure refactor of request timeout and body parsing in the mock callback wrapper; low risk aside from potential edge-case differences when timeout tuples or unusual body types are passed.

Overview
Refactors _wrap_callback in src/mock_vws/_requests_mock_server/decorators.py to replace isinstance chains with match/case for (1) normalizing requests timeout values (including (connect, read) tuples) into an effective read-timeout and (2) converting request.body into bytes.

Behavior is intended to stay the same, but tuple handling is now pattern-matched (only treating (…, number) as a read timeout) and body handling is expressed via explicit None/str cases with a fallback to the original body value.

Reviewed by Cursor Bugbot for commit 3d57724. Bugbot is set up for automated code reviews on this repo. Configure here.

Replace isinstance chains with match/case for timeout normalization
and request body conversion in _wrap_callback.

Closes #3110

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread src/mock_vws/_requests_mock_server/decorators.py Outdated
The original else branch handled any type, not just bytes(). Using
case _ preserves that catch-all semantics.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b4cfed0. Configure here.

Comment thread src/mock_vws/_requests_mock_server/decorators.py
Match only int/float read values in the tuple case, so (5, None)
falls through to effective = None instead of raising TypeError.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Refactor _wrap_callback timeout and body handling with match

1 participant