Repository navigation
fix: annotate client timeouts as float - #1106
Merged
Merged
Conversation
`timeout` and `feature_flags_request_timeout_seconds` were typed (or inferred) as `int`, so type checkers rejected fractional values even though they go straight to requests/httpx, which accept floats. Fixes #1089 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
posthog-python Compliance ReportDate: 2026-10-22T16:50:58.650821+00:00 ✅ All Tests Passed!121/121 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
dustinbyrne
approved these changes
Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Fixes #1089.
timeoutandfeature_flags_request_timeout_secondsare annotated asintonAsyncClientand the request helpers. OnClientandConsumerthey have no annotation, so type checkers inferintfrom the defaults. As a result,timeout=2.5fails type checks even though both values go straight torequests/httpx, which accept floats. Newer APIs already usefloat:OfflineEvaluations(timeout: float = 15)andflush(timeout_seconds: Optional[float]).This PR annotates both options as
floateverywhere they're declared or passed through:Client,AsyncClient,Consumerand_AsyncConsumerposthog.request,posthog._async_requestandposthog.capture_v1posthog.feature_flags_request_timeout_secondsmodule defaultTwo non-SDK files needed the same change so mypy stays clean:
typings/requests/__init__.pyi: our local stub typedSession.post/gettimeoutasint, which is narrower than realrequests. The stub's ownSession.requestalready usedfloat.sdk_compliance_adapter/adapter.py: itsbatch_post/post_v1wrappers replace the SDK functions, so their signatures have to match.Public API
The snapshot diff is annotation-only (8 lines). Runtime behavior and defaults are unchanged, and type checkers still accept existing
intarguments. The only code that could see a new static-typing error reads these values back asint, or replaces the request helpers withint-typed functions. Shipping as a patch.💚 How did you test it?
pytest posthog/test --timeout=30: 5135 passed. This ran before the final stub and adapter edits. The focusedsdk_compliance_adapter,test_request.pyandtest_capture_v1.pyrun after those edits: 189 passed.mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter: no new errors in tracked filesruff format --check,ruff check,make public_api_checkandpython -W error -c "import posthog"all passNo new tests, because nothing changes at runtime. The mypy check is what guards this change.
📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
timeoutclient initializer isint#1089 againstmain, then made the annotation change across the SDK. mypy flagged the localrequestsstub and the compliance adapter, so they were widened to match.typings/requestskeeps its other narrow signatures. Onlytimeoutwas widened.🤖 Generated with Claude Code