Skip to content

[Types] Type custom sub-client properties so pyright sees construct_event, realtime, convert_realtime - #887

Merged
brandonrule11 merged 1 commit into
mainfrom
brandonrule/flo-324-python-sdk-type-checkers-reject
Oct 14, 2026
Merged

brandonrule11 merged 1 commit into
mainfrom
brandonrule/flo-324-python-sdk-type-checkers-reject

Conversation

@brandonrule11

Copy link
Copy Markdown
Contributor

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.py assigns custom subclasses to self._webhooks / _music / _speech_to_text / _text_to_speech, but only re-declares a typed property for speech_engine. The other names fall through to base_client.py's unannotated properties, which pyright infers as the autogenerated clients.

Fix: re-declare each property with a typing.cast to the custom client, matching the existing speech_engine property.

Notes

  • Also typed text_to_speech (sync only). The ticket names webhooks, music and speech_to_text, but text_to_speech.convert_realtime has the same bug. The async client has no custom TTS subclass, so it is unchanged.
  • mypy didn't catch this, which is why CI was green. mypy treats the unannotated base properties as Any. Only pyright/basedpyright report the error.
  • The regression test checks annotations at runtime instead of running pyright. tests/test_client_types.py asserts 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_detailed didn't error before, because the generated client also defines it, but its return type was the generated one. It now resolves to the custom MultipartResponse-returning override.

Testing

  • Repro script calling construct_event, realtime and convert_realtime on both clients: pyright reported 5 errors on main and 0 with this change.
  • tests/test_client_types.py: 7 of its 10 cases fail with the client.py change 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 on main.

🤖 Generated with Claude Code

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>
@cursor

cursor Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Typing-only surface changes with no runtime behavior change beyond explicit property overrides; low risk aside from possible annotation mismatches if custom clients diverge from assignments.

Overview
Fixes pyright rejecting SDK-only APIs such as client.webhooks.construct_event, text_to_speech.convert_realtime, and related custom sub-client methods even though they work at runtime.

ElevenLabs and AsyncElevenLabs now re-declare sub-client @property accessors with explicit return types and typing.cast to the custom wrapper classes (WebhooksClient, MusicClient, SpeechToTextClient, and sync RealtimeTextToSpeechClient), following the existing speech_engine pattern. That overrides the unannotated base-client properties pyright was inferring as autogenerated clients.

Adds tests/test_client_types.py to assert each property’s return annotation and runtime instance type, plus that construct_event remains callable on sync and async clients.

Reviewed by Cursor Bugbot for commit 4a2d09b. Bugbot is set up for automated code reviews on this repo. Configure here.

@brandonrule11
brandonrule11 merged commit 553a3d0 into main Oct 14, 2026
4 checks passed
@brandonrule11
brandonrule11 deleted the brandonrule/flo-324-python-sdk-type-checkers-reject branch October 14, 2026 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants