You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the asynchronous transport layer for MLB Stats API requests while preserving the behavioral contract established for the synchronous adapter.
Async context-manager support is not part of AsyncMlbDataAdapter in #301. Public async with AsyncMlb() lifecycle support belongs to the AsyncMlb vertical slice in #303. The adapter only needs correct explicit aclose() ownership and cleanup semantics here.
Add a focused implementation test suite in tests/test_async_mlb_dataadapter.py that proves the adapter behavior implemented in this issue. The exhaustive async transport contract matrix remains the responsibility of #302.
Basic success
200 JSON response returns an MlbResult
Successful empty response body becomes {}
HTTP contract
404 returns an empty MlbResult
Strict non-404 4xx raises MlbHttpError
Compatibility-mode non-404 4xx emits MlbHttpCompatibilityWarning and returns an empty result
Final 5xx raises MlbHttpError
Structured HTTP error context is preserved where available
Exceptions
HTTPX timeout maps to MlbTimeoutError
Other HTTPX request/transport failures map to MlbTransportError
Invalid JSON on a successful response raises MlbDecodeError
Lifecycle and ownership
Library-owned client is closed by aclose()
aclose() is idempotent
Caller-injected client is not closed
Caller-injected client configuration is not mutated
Configuration
Scalar timeout values are translated correctly
(connect, read) timeout tuples are translated correctly
Library-owned client receives the package User-Agent
Caller-injected client headers remain unchanged
Async behavior
Caller cancellation propagates as asyncio.CancelledError
Multiple basic concurrent requests can safely share the same adapter/client
Transient retryable failure can succeed on a later attempt
Retry exhaustion raises the correct public error
Retry backoff is awaitable and does not block the event loop
The purpose of these tests is to prove the implementation built in #301. Issue #302 should then expand this into the deterministic, exhaustive transport-contract suite used to prevent long-term sync/async drift.
Compatibility
Equivalent responses should map to the same public MlbResult and exception hierarchy used by the synchronous transport wherever practical.
Caller-owned clients must not be closed or unexpectedly reconfigured by the library.
Parent: #297
Depends on: #298, #300
Goal
Implement the asynchronous transport layer for MLB Stats API requests while preserving the behavioral contract established for the synchronous adapter.
Scope
Implement
AsyncMlbDataAdapterwith:aclose()cleanupstrict_http=Falsecompatibility behaviorOut of scope
Async context-manager support is not part of
AsyncMlbDataAdapterin #301. Publicasync with AsyncMlb()lifecycle support belongs to theAsyncMlbvertical slice in #303. The adapter only needs correct explicitaclose()ownership and cleanup semantics here.Contract requirements from #298
Lifecycle and ownership
aclose()aclose()is idempotentTimeout and transport failures
timeoutpublic shape, including scalar values and(connect, read)tuplesDEFAULT_TIMEOUT = (3.05, 30.0)MlbTimeoutErrorMlbTransportErrorHTTP behavior
After retries are exhausted:
MlbHttpErrorcontext where available: status, reason, URL, method, and bounded best-effort response contextMlbHttpErrorJSON behavior
{}throughMlbResultMlbDecodeErrorRetry behavior
For library-owned clients:
429,500,502,503,5040.5backoff policyRetry-AfterCaller-injected clients retain caller-controlled retry configuration.
User-Agent
python-mlb-statsapi/<installed-version>with the existingunknownfallbackConcurrency
Focused #301 test coverage
Add a focused implementation test suite in
tests/test_async_mlb_dataadapter.pythat proves the adapter behavior implemented in this issue. The exhaustive async transport contract matrix remains the responsibility of #302.Basic success
MlbResult{}HTTP contract
MlbResultMlbHttpErrorMlbHttpCompatibilityWarningand returns an empty resultMlbHttpErrorExceptions
MlbTimeoutErrorMlbTransportErrorMlbDecodeErrorLifecycle and ownership
aclose()aclose()is idempotentConfiguration
(connect, read)timeout tuples are translated correctlyAsync behavior
asyncio.CancelledErrorThe purpose of these tests is to prove the implementation built in #301. Issue #302 should then expand this into the deterministic, exhaustive transport-contract suite used to prevent long-term sync/async drift.
Compatibility
Equivalent responses should map to the same public
MlbResultand exception hierarchy used by the synchronous transport wherever practical.Caller-owned clients must not be closed or unexpectedly reconfigured by the library.
Acceptance criteria
AsyncMlbDataAdapterimplementation tests cover the behavior delivered in Implement AsyncMlbDataAdapter #301aclose()is idempotentRefs #297
Contract: #298