Skip to content

Commit 9f377b1

Browse files
committed
fix async and unused type errors
1 parent 26c802c commit 9f377b1

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

livekit-api/livekit/api/access_token.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@ def verify(self, token: str, *, verify_signature: bool = True) -> Claims:
278278
return grant_claims
279279

280280

281-
def camel_to_snake(t: str):
281+
def camel_to_snake(t: str) -> str:
282282
return re.sub(r"(?<!^)(?=[A-Z])", "_", t).lower()
283283

284284

285-
def snake_to_lower_camel(t: str):
285+
def snake_to_lower_camel(t: str) -> str:
286286
return "".join(word.capitalize() if i else word for i, word in enumerate(t.split("_")))

livekit-api/livekit/api/livekit_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .sip_service import SipService
77
from .agent_dispatch_service import AgentDispatchService
88
from .connector_service import ConnectorService
9-
from typing import Optional
9+
from typing import Any, Optional
1010

1111

1212
class LiveKitAPI:
@@ -96,21 +96,21 @@ def connector(self) -> ConnectorService:
9696
"""Instance of the ConnectorService"""
9797
return self._connector
9898

99-
async def aclose(self):
99+
async def aclose(self) -> None:
100100
"""Close the API client
101101
102102
Call this before your application exits or when the API client is no longer needed."""
103103
# we do not close custom sessions, that's up to the caller
104-
if not self._custom_session:
104+
if not self._custom_session and self._session is not None:
105105
await self._session.close()
106106

107-
async def __aenter__(self):
107+
async def __aenter__(self) -> "LiveKitAPI":
108108
"""@private
109109
110110
Support for `async with`"""
111111
return self
112112

113-
async def __aexit__(self, exc_type, exc_val, exc_tb):
113+
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
114114
"""@private
115115
116116
Support for `async with`"""

livekit-rtc/livekit/rtc/audio_stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
num_channels: int = 1,
6666
frame_size_ms: int | None = None,
6767
noise_cancellation: Optional[NoiseCancellationOptions | FrameProcessor[AudioFrame]] = None,
68-
**kwargs,
68+
**kwargs: Any,
6969
) -> None:
7070
"""Initialize an `AudioStream` instance.
7171
@@ -266,7 +266,7 @@ def _create_owned_stream_from_participant(
266266
resp = FfiClient.instance.request(req)
267267
return resp.audio_stream_from_participant.stream
268268

269-
async def _run(self):
269+
async def _run(self) -> None:
270270
while True:
271271
event = await self._ffi_queue.wait_for(self._is_event)
272272
audio_event: proto_audio_frame.AudioStreamEvent = event.audio_stream_event

livekit-rtc/livekit/rtc/data_stream.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def __init__(
6666
)
6767
self._queue: asyncio.Queue[proto_DataStream.Chunk | None] = asyncio.Queue()
6868

69-
async def _on_chunk_update(self, chunk: proto_DataStream.Chunk):
69+
async def _on_chunk_update(self, chunk: proto_DataStream.Chunk) -> None:
7070
await self._queue.put(chunk)
7171

72-
async def _on_stream_close(self, trailer: proto_DataStream.Trailer):
72+
async def _on_stream_close(self, trailer: proto_DataStream.Trailer) -> None:
7373
self.info.attributes = self.info.attributes or {}
7474
self.info.attributes.update(trailer.attributes)
7575
await self._queue.put(None)
@@ -114,10 +114,10 @@ def __init__(self, header: proto_DataStream.Header, capacity: int = 0) -> None:
114114
)
115115
self._queue: asyncio.Queue[proto_DataStream.Chunk | None] = asyncio.Queue(capacity)
116116

117-
async def _on_chunk_update(self, chunk: proto_DataStream.Chunk):
117+
async def _on_chunk_update(self, chunk: proto_DataStream.Chunk) -> None:
118118
await self._queue.put(chunk)
119119

120-
async def _on_stream_close(self, trailer: proto_DataStream.Trailer):
120+
async def _on_stream_close(self, trailer: proto_DataStream.Trailer) -> None:
121121
self.info.attributes = self.info.attributes or {}
122122
self.info.attributes.update(trailer.attributes)
123123
await self._queue.put(None)
@@ -166,7 +166,7 @@ def __init__(
166166
self._sender_identity = sender_identity or self._local_participant.identity
167167
self._closed = False
168168

169-
async def _send_header(self):
169+
async def _send_header(self) -> None:
170170
req = proto_ffi.FfiRequest(
171171
send_stream_header=proto_room.SendStreamHeaderRequest(
172172
header=self._header,
@@ -188,7 +188,7 @@ async def _send_header(self):
188188
if cb.send_stream_header.error:
189189
raise ConnectionError(cb.send_stream_header.error)
190190

191-
async def _send_chunk(self, chunk: proto_DataStream.Chunk):
191+
async def _send_chunk(self, chunk: proto_DataStream.Chunk) -> None:
192192
if self._closed:
193193
raise RuntimeError(f"Cannot send chunk after stream is closed: {chunk}")
194194
req = proto_ffi.FfiRequest(
@@ -212,7 +212,7 @@ async def _send_chunk(self, chunk: proto_DataStream.Chunk):
212212
if cb.send_stream_chunk.error:
213213
raise ConnectionError(cb.send_stream_chunk.error)
214214

215-
async def _send_trailer(self, trailer: proto_DataStream.Trailer):
215+
async def _send_trailer(self, trailer: proto_DataStream.Trailer) -> None:
216216
req = proto_ffi.FfiRequest(
217217
send_stream_trailer=proto_room.SendStreamTrailerRequest(
218218
trailer=trailer,
@@ -233,7 +233,7 @@ async def _send_trailer(self, trailer: proto_DataStream.Trailer):
233233
if cb.send_stream_chunk.error:
234234
raise ConnectionError(cb.send_stream_trailer.error)
235235

236-
async def aclose(self, *, reason: str = "", attributes: Optional[Dict[str, str]] = None):
236+
async def aclose(self, *, reason: str = "", attributes: Optional[Dict[str, str]] = None) -> None:
237237
if self._closed:
238238
raise RuntimeError("Stream already closed")
239239
self._closed = True
@@ -281,7 +281,7 @@ def __init__(
281281
)
282282
self._write_lock = asyncio.Lock()
283283

284-
async def write(self, text: str):
284+
async def write(self, text: str) -> None:
285285
async with self._write_lock:
286286
for chunk in split_utf8(text, STREAM_CHUNK_SIZE):
287287
content = chunk
@@ -333,7 +333,7 @@ def __init__(
333333
)
334334
self._write_lock = asyncio.Lock()
335335

336-
async def write(self, data: bytes):
336+
async def write(self, data: bytes) -> None:
337337
async with self._write_lock:
338338
chunked_data = [
339339
data[i : i + STREAM_CHUNK_SIZE] for i in range(0, len(data), STREAM_CHUNK_SIZE)

livekit-rtc/livekit/rtc/participant.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from .rpc import RpcInvocationData
5050
from .data_stream import (
5151
TextStreamWriter,
52+
TextStreamInfo,
5253
ByteStreamWriter,
5354
ByteStreamInfo,
5455
STREAM_CHUNK_SIZE,
@@ -160,7 +161,7 @@ def __init__(
160161
) -> None:
161162
super().__init__(owned_info)
162163
self._room_queue = room_queue
163-
self._track_publications: dict[str, LocalTrackPublication] = {} # type: ignore
164+
self._track_publications: dict[str, LocalTrackPublication] = {}
164165
self._rpc_handlers: Dict[str, RpcHandler] = {}
165166

166167
@property
@@ -327,7 +328,7 @@ async def perform_rpc(
327328
if cb.perform_rpc.HasField("error"):
328329
raise RpcError._from_proto(cb.perform_rpc.error)
329330

330-
return cb.perform_rpc.payload
331+
return cast(str, cb.perform_rpc.payload)
331332

332333
def register_rpc_method(
333334
self,
@@ -587,7 +588,7 @@ async def send_text(
587588
topic: str = "",
588589
attributes: Optional[Dict[str, str]] = None,
589590
reply_to_id: str | None = None,
590-
):
591+
) -> TextStreamInfo:
591592
total_size = len(text.encode())
592593
writer = await self.stream_text(
593594
destination_identities=destination_identities,
@@ -743,7 +744,7 @@ def __repr__(self) -> str:
743744
class RemoteParticipant(Participant):
744745
def __init__(self, owned_info: proto_participant.OwnedParticipant) -> None:
745746
super().__init__(owned_info)
746-
self._track_publications: dict[str, RemoteTrackPublication] = {} # type: ignore
747+
self._track_publications: dict[str, RemoteTrackPublication] = {}
747748

748749
@property
749750
def track_publications(self) -> Mapping[str, RemoteTrackPublication]:

livekit-rtc/livekit/rtc/room.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ def on_participant_connected(participant):
470470
if options.rtc_config:
471471
req.connect.options.rtc_config.ice_transport_type = (
472472
options.rtc_config.ice_transport_type
473-
) # type: ignore
473+
)
474474
req.connect.options.rtc_config.continual_gathering_policy = (
475475
options.rtc_config.continual_gathering_policy
476-
) # type: ignore
476+
)
477477
req.connect.options.rtc_config.ice_servers.extend(options.rtc_config.ice_servers)
478478

479479
# subscribe before connecting so we don't miss any events
@@ -540,25 +540,25 @@ async def get_rtc_stats(self) -> RtcStats:
540540

541541
return RtcStats(publisher_stats=publisher_stats, subscriber_stats=subscriber_stats)
542542

543-
def register_byte_stream_handler(self, topic: str, handler: ByteStreamHandler):
543+
def register_byte_stream_handler(self, topic: str, handler: ByteStreamHandler) -> None:
544544
existing_handler = self._byte_stream_handlers.get(topic)
545545
if existing_handler is None:
546546
self._byte_stream_handlers[topic] = handler
547547
else:
548548
raise ValueError("byte stream handler for topic '%s' already set" % topic)
549549

550-
def unregister_byte_stream_handler(self, topic: str):
550+
def unregister_byte_stream_handler(self, topic: str) -> None:
551551
if self._byte_stream_handlers.get(topic):
552552
self._byte_stream_handlers.pop(topic)
553553

554-
def register_text_stream_handler(self, topic: str, handler: TextStreamHandler):
554+
def register_text_stream_handler(self, topic: str, handler: TextStreamHandler) -> None:
555555
existing_handler = self._text_stream_handlers.get(topic)
556556
if existing_handler is None:
557557
self._text_stream_handlers[topic] = handler
558558
else:
559559
raise ValueError("text stream handler for topic '%s' already set" % topic)
560560

561-
def unregister_text_stream_handler(self, topic: str):
561+
def unregister_text_stream_handler(self, topic: str) -> None:
562562
if self._text_stream_handlers.get(topic):
563563
self._text_stream_handlers.pop(topic)
564564

@@ -618,7 +618,7 @@ async def _listen_task(self) -> None:
618618
await self._drain_rpc_invocation_tasks()
619619
await self._drain_data_stream_tasks()
620620

621-
def _on_rpc_method_invocation(self, rpc_invocation: RpcMethodInvocationEvent):
621+
def _on_rpc_method_invocation(self, rpc_invocation: RpcMethodInvocationEvent) -> None:
622622
if self._local_participant is None:
623623
return
624624

@@ -636,7 +636,7 @@ def _on_rpc_method_invocation(self, rpc_invocation: RpcMethodInvocationEvent):
636636
self._rpc_invocation_tasks.add(task)
637637
task.add_done_callback(self._rpc_invocation_tasks.discard)
638638

639-
def _on_room_event(self, event: proto_room.RoomEvent):
639+
def _on_room_event(self, event: proto_room.RoomEvent) -> None:
640640
which = event.WhichOneof("message")
641641
if which == "participant_connected":
642642
rparticipant = self._create_remote_participant(event.participant_connected.info)
@@ -905,7 +905,7 @@ def _on_room_event(self, event: proto_room.RoomEvent):
905905

906906
def _handle_stream_header(
907907
self, header: proto_room.DataStream.Header, participant_identity: str
908-
):
908+
) -> None:
909909
stream_type = header.WhichOneof("content_header")
910910
if stream_type == "text_header":
911911
text_stream_handler = self._text_stream_handlers.get(header.topic)
@@ -935,7 +935,7 @@ def _handle_stream_header(
935935
logging.warning("received unknown header type, %s", stream_type)
936936
pass
937937

938-
async def _handle_stream_chunk(self, chunk: proto_room.DataStream.Chunk):
938+
async def _handle_stream_chunk(self, chunk: proto_room.DataStream.Chunk) -> None:
939939
text_reader = self._text_stream_readers.get(chunk.stream_id)
940940
file_reader = self._byte_stream_readers.get(chunk.stream_id)
941941

@@ -944,7 +944,7 @@ async def _handle_stream_chunk(self, chunk: proto_room.DataStream.Chunk):
944944
elif file_reader:
945945
await file_reader._on_chunk_update(chunk)
946946

947-
async def _handle_stream_trailer(self, trailer: proto_room.DataStream.Trailer):
947+
async def _handle_stream_trailer(self, trailer: proto_room.DataStream.Trailer) -> None:
948948
text_reader = self._text_stream_readers.get(trailer.stream_id)
949949
file_reader = self._byte_stream_readers.get(trailer.stream_id)
950950

0 commit comments

Comments
 (0)