Pyright flagged 19 sites where `await self._<connection>.send/recv/...` was called on a receiver typed `X | None`. Each kind of call site needed a slightly different fix to be both type-safe and behaviour- preserving: Streaming/user-facing paths (early return + warn — drop and warn is the right runtime fail-safe when reconnect didn't succeed): - cartesia/stt.py (run_stt) - soniox/stt.py (_send_keepalive) - elevenlabs/tts.py (run_tts — yields ErrorFrame and returns) - deepgram/sagemaker/tts.py (run_tts) - transports/lemonslice/transport.py (send_message) - transports/tavus/transport.py (send_message) "Should never happen" cases (early return with comment, no warn — caller already gated on a separate `_is_*` check, so a warn would be noise): - deepgram/flux/stt.py (transport methods, gated by _transport_is_active) - deepgram/flux/sagemaker/stt.py (same) - stt_service.py (_send_keepalive, gated by _is_keepalive_ready) - elevenlabs/stt.py (_send_keepalive, same) - llm_service.py (_ws_recv — raises ConnectionError to match _ensure_connected's contract) - heygen/client.py (receive loop, gated by self._connected) Just-assigned-above (use a local variable so pyright keeps the narrowing across statements): - lmnt/tts.py - gradium/stt.py - fish/tts.py Other: - transports/websocket/server.py — used the existing local `websocket` parameter in scope instead of `self._websocket` for the close call. - websocket_service.py — `send_with_retry` raises ConnectionError when `self._websocket` is None inside the existing try-block, so the broad `except Exception` triggers reconnect just as it would on a real send failure (preserving the prior behaviour where None silently fell through to the AttributeError-driven reconnect path). Drops three now-clean files from the pyright ignore list: cartesia/stt.py, elevenlabs/stt.py, and soniox/stt.py.
5.2 KiB
5.2 KiB