Fix TypeError by extracting numeric attributes from Timeout obect in …
69
1mo ago+6+6+0123456789-0-0-0123456789
Summary
This Pull Request resolves a TypeError where a Timeout object cannot be interpreted as an integer within the synchronous connect_tcp backend loop (Issue #1162).
Root Cause Analysis
When a synchronous request carries a structured Timeout configuration object inside its transport extensions dictionary metadata, the transport backend engine fails to extract the underlying numerical value. It attempts to feed the wrapper object directly into system socket blocks expecting raw integers or floats, resulting in a terminal application crash.
Changes Made
- Added a type-checking validation filter at the head of
connect_tcp()withinsrc/httpcore2/httpcore2/_backends/sync.py. - Implemented an attribute detection check using
hasattr()to gracefully unpack.connector.totalnumeric floating properties from customTimeoutconfigurations. - Added comprehensive unit test verification suites to ensure robustness against malformed or compound configuration extensions.
Testing Performed
- Validated clean script compilation status via
python -m py_compile. - Executed
pytestlocal suites to confirm that all test pipelines finish successfully with a green status.
Checklist
- I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
- I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
- I've updated the documentation accordingly.