feat(client): configurable timeout and retry settings (Closes #5)#31
Conversation
Add global shade.timeout and shade.max_retries backed by config.py, validate settings on client construction, and resolve per-instance ShadeClient/Gateway overrides with module-level defaults. Closes ShadeProtocol#5
📝 WalkthroughWalkthroughThe package adds shared timeout and retry settings with defaults and validation. ChangesConfigurable client timeout and retry settings
Sequence Diagram(s)sequenceDiagram
participant shade
participant config
participant validate_client_settings
participant Gateway
participant SyncHTTPClient
participant AsyncHTTPClient
shade->>config: set timeout and max_retries
Gateway->>config: read defaults when arguments are None
Gateway->>validate_client_settings: validate resolved timeout and max_retries
Gateway->>SyncHTTPClient: pass resolved timeout and max_retries
Gateway->>AsyncHTTPClient: pass resolved timeout and max_retries
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shade/__init__.py (1)
60-73: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider validating in the
timeout/max_retriessetters.These setters write straight to
_configwithout validation, soshade.timeout = 0orshade.max_retries = -1succeeds silently and only fails later when a client is constructed. Validating at assignment time gives the user a clear, immediate error at the point of the mistake.♻️ Validate on assignment
`@timeout.setter` def timeout(self, value: float) -> None: from . import config as _config + _config.validate_client_settings(value, _config.max_retries) _config.timeout = value @@ `@max_retries.setter` def max_retries(self, value: int) -> None: from . import config as _config + _config.validate_client_settings(_config.timeout, value) _config.max_retries = value🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/shade/__init__.py` around lines 60 - 73, The timeout and max_retries setters in shade.__init__.py currently assign directly to _config without any guard, so invalid values can slip through until client creation; add assignment-time validation in the timeout and max_retries property setters to reject non-positive timeout values and negative retry counts with an immediate, clear error. Use the existing timeout, max_retries, and config property setters as the place to enforce the checks so invalid values fail at the point of assignment rather than later.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/shade/__init__.py`:
- Around line 60-73: The timeout and max_retries setters in shade.__init__.py
currently assign directly to _config without any guard, so invalid values can
slip through until client creation; add assignment-time validation in the
timeout and max_retries property setters to reject non-positive timeout values
and negative retry counts with an immediate, clear error. Use the existing
timeout, max_retries, and config property setters as the place to enforce the
checks so invalid values fail at the point of assignment rather than later.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2344b7c1-32c5-4678-a837-fa80bd53f223
📒 Files selected for processing (5)
src/shade/__init__.pysrc/shade/config.pysrc/shade/gateway.pysrc/shade/http.pytests/test_client_settings.py
Summary
Closes #5
Adds global and per-instance timeout/retry configuration for
ShadeClient(Gateway):shade.timeoutandshade.max_retriesmodule-level settings backed byconfig.pyShadeClient(timeout=..., max_retries=...)timeout > 0and0 <= max_retries <= 10SyncHTTPClient/AsyncHTTPClienttransport layersAcceptance criteria
ShadeClient(timeout=5.0)times out after 5 secondsShadeClient(max_retries=0)disables retriesValueErrorshade.timeout/shade.max_retriesrespectedTest plan
poetry run pytest -v— 81/81 passedSummary by CodeRabbit
New Features
timeoutandmax_retriessettings at the module level and per client.Bug Fixes
0, and timeout settings are passed through consistently.