Repository navigation
[Types] Type custom sub-client properties so pyright sees construct_event, realtime, convert_realtime - #887
Conversation
The wrapper swaps in custom webhooks, music, speech_to_text and (sync) text_to_speech clients, but only re-declared a typed property for speech_engine. The others fell through to the base client's unannotated properties, which pyright infers as the autogenerated clients, so `client.webhooks.construct_event` and similar failed type checking. Fixes FLO-324. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR SummaryLow Risk Overview
Adds Reviewed by Cursor Bugbot for commit 4a2d09b. Bugbot is set up for automated code reviews on this repo. Configure here. |
Fixes FLO-324.
client.webhooks.construct_event(...)works at runtime but pyright rejects it on 2.70.0 (Attribute "construct_event" is unknown). That breaks anyone type-checking the webhook handler from the templates quickstart, and it breaks the xi snippet e2e test that typechecks the generated handler.Cause:
client.pyassigns custom subclasses toself._webhooks/_music/_speech_to_text/_text_to_speech, but only re-declares a typed property forspeech_engine. The other names fall through tobase_client.py's unannotated properties, which pyright infers as the autogenerated clients.Fix: re-declare each property with a
typing.castto the custom client, matching the existingspeech_engineproperty.Notes
text_to_speech(sync only). The ticket names webhooks, music and speech_to_text, buttext_to_speech.convert_realtimehas the same bug. The async client has no custom TTS subclass, so it is unchanged.Any. Only pyright/basedpyright report the error.tests/test_client_types.pyasserts each property's return annotation and runtime type. Adding pyright to dev deps and CI would be a bigger change than this ticket needs; happy to follow up if wanted.music.compose_detaileddidn't error before, because the generated client also defines it, but its return type was the generated one. It now resolves to the customMultipartResponse-returning override.Testing
construct_event,realtimeandconvert_realtimeon both clients: pyright reported 5 errors onmainand 0 with this change.tests/test_client_types.py: 7 of its 10 cases fail with theclient.pychange reverted, and all pass with it.mypy .: clean.pytest tests: 16 failures, all live-API tests that need a real API key. The same 16 fail onmain.🤖 Generated with Claude Code