Skip to content

Commit 1994d60

Browse files
committed
fix remaining type errors
1 parent 9f377b1 commit 1994d60

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

livekit-rtc/livekit/rtc/_ffi_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import platform
2525
import atexit
2626
import threading
27-
from typing import Generic, List, Optional, TypeVar
27+
from typing import Any, Generic, List, Optional, TypeVar
2828

2929
from ._proto import ffi_pb2 as proto_ffi
3030
from ._utils import Queue, classproperty
@@ -34,7 +34,7 @@
3434
atexit.register(_resource_files.close)
3535

3636

37-
def get_ffi_lib():
37+
def get_ffi_lib() -> ctypes.CDLL:
3838
# allow to override the lib path using an env var
3939
libpath = os.environ.get("LIVEKIT_LIB_PATH", "").strip()
4040
if libpath:
@@ -92,7 +92,7 @@ def __init__(self, handle: int) -> None:
9292
self.handle = handle
9393
self._disposed = False
9494

95-
def __del__(self):
95+
def __del__(self) -> None:
9696
self.dispose()
9797

9898
@property
@@ -142,7 +142,7 @@ def unsubscribe(self, queue: Queue[T]) -> None:
142142
break
143143

144144

145-
@ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.c_uint8), ctypes.c_size_t)
145+
@ctypes.CFUNCTYPE(None, ctypes.POINTER(ctypes.c_uint8), ctypes.c_size_t) # type: ignore[untyped-decorator]
146146
def ffi_event_callback(
147147
data_ptr: ctypes.POINTER(ctypes.c_uint8), # type: ignore
148148
data_len: ctypes.c_size_t,
@@ -219,7 +219,7 @@ def __init__(self) -> None:
219219
)
220220

221221
@atexit.register
222-
def _dispose_lk_ffi():
222+
def _dispose_lk_ffi() -> None:
223223
ffi_lib.livekit_ffi_dispose()
224224

225225
@property

livekit-rtc/livekit/rtc/_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
from collections import deque
1818
import ctypes
1919
import random
20-
from typing import Callable, Generator, Generic, List, TypeVar
20+
from typing import Any, Callable, Generator, Generic, List, TypeVar
2121

2222
logger = logging.getLogger("livekit")
2323

2424

2525
class classproperty(object):
26-
def __init__(self, f):
27-
self.f = classmethod(f)
26+
def __init__(self, f: Callable[..., Any]) -> None:
27+
self.f: Any = classmethod(f)
2828

29-
def __get__(self, *a):
29+
def __get__(self, *a: Any) -> Any:
3030
return self.f.__get__(*a)()
3131

3232

@@ -118,7 +118,7 @@ async def join(self) -> None:
118118
_base62_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
119119

120120

121-
def generate_random_base62(length=12):
121+
def generate_random_base62(length: int = 12) -> str:
122122
"""
123123
Generate a random base62 encoded string of a specified length.
124124

livekit-rtc/livekit/rtc/e2ee.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from dataclasses import dataclass, field
16-
from typing import List, Optional
16+
from typing import List, Optional, cast
1717

1818
from ._ffi_client import FfiClient
1919
from ._proto import e2ee_pb2 as proto_e2ee
@@ -84,7 +84,7 @@ def export_shared_key(self, key_index: int) -> bytes:
8484
req.e2ee.get_shared_key.key_index = key_index
8585
resp = FfiClient.instance.request(req)
8686
key = resp.e2ee.get_shared_key.key
87-
return key
87+
return cast(bytes, key)
8888

8989
def ratchet_shared_key(self, key_index: int) -> bytes:
9090
"""Ratchets the shared encryption key to a new key.
@@ -107,7 +107,7 @@ def ratchet_shared_key(self, key_index: int) -> bytes:
107107
resp = FfiClient.instance.request(req)
108108

109109
new_key = resp.e2ee.ratchet_shared_key.new_key
110-
return new_key
110+
return cast(bytes, new_key)
111111

112112
def set_key(self, participant_identity: str, key: bytes, key_index: int) -> None:
113113
"""Sets the encryption key for a specific participant.
@@ -152,7 +152,7 @@ def export_key(self, participant_identity: str, key_index: int) -> bytes:
152152
req.e2ee.get_key.key_index = key_index
153153
resp = FfiClient.instance.request(req)
154154
key = resp.e2ee.get_key.key
155-
return key
155+
return cast(bytes, key)
156156

157157
def ratchet_key(self, participant_identity: str, key_index: int) -> bytes:
158158
"""Ratchets the encryption key for a specific participant to a new key.
@@ -176,7 +176,7 @@ def ratchet_key(self, participant_identity: str, key_index: int) -> bytes:
176176

177177
resp = FfiClient.instance.request(req)
178178
new_key = resp.e2ee.ratchet_key.new_key
179-
return new_key
179+
return cast(bytes, new_key)
180180

181181

182182
class FrameCryptor:

livekit-rtc/livekit/rtc/jupyter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def room_html(url: str, token: str, *, width: str, height: str) -> HTML:
5050
f'srcdoc="{escaped_content}"></iframe>'
5151
)
5252

53-
return HTML(html_text)
53+
return HTML(html_text) # type: ignore[no-untyped-call]
5454

5555

5656
def display_room(url: str, token: str, *, width: str = "100%", height: str = "110px") -> None:
@@ -65,4 +65,4 @@ def display_room(url: str, token: str, *, width: str = "100%", height: str = "11
6565
The rendered HTML will include the provided `url` and `token` in plain text.
6666
Avoid using sensitive tokens in public notebooks (e.g., tokens with long expiration times).
6767
"""
68-
display(room_html(url, token, width=width, height=height))
68+
display(room_html(url, token, width=width, height=height)) # type: ignore[no-untyped-call]

livekit-rtc/livekit/rtc/media_devices.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import threading
2323

2424
if TYPE_CHECKING:
25-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
25+
import sounddevice as sd # type: ignore[import-not-found]
2626

2727
from . import AudioSource
2828
from .audio_frame import AudioFrame
@@ -163,7 +163,7 @@ def __init__(
163163
output_device: Optional[int] = None,
164164
delay_estimator: Optional[_APMDelayEstimator] = None,
165165
) -> None:
166-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
166+
import sounddevice as sd
167167

168168
self._sample_rate = sample_rate
169169
self._num_channels = num_channels
@@ -303,16 +303,17 @@ async def start(self) -> None:
303303
if self._mixer is None:
304304
self._mixer = AudioMixer(sample_rate=self._sample_rate, num_channels=self._num_channels)
305305

306-
async def _playback_loop():
306+
async def _playback_loop() -> None:
307307
"""Internal playback loop that consumes frames from the mixer."""
308308
self._running = True
309309
self._stream.start()
310310
try:
311-
async for frame in self._mixer:
312-
if not self._running:
313-
break
314-
# Append raw PCM bytes for callback consumption
315-
self._buffer.extend(frame.data.tobytes())
311+
if self._mixer is not None:
312+
async for frame in self._mixer:
313+
if not self._running:
314+
break
315+
# Append raw PCM bytes for callback consumption
316+
self._buffer.extend(frame.data.tobytes())
316317
finally:
317318
self._running = False
318319
try:
@@ -402,7 +403,7 @@ def list_input_devices(self) -> list[dict[str, Any]]:
402403
Returns a list of dictionaries with the `sounddevice` metadata and an
403404
added `index` key corresponding to the device index.
404405
"""
405-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
406+
import sounddevice as sd
406407

407408
devices = sd.query_devices()
408409
result: list[dict[str, Any]] = []
@@ -413,7 +414,7 @@ def list_input_devices(self) -> list[dict[str, Any]]:
413414

414415
def list_output_devices(self) -> list[dict[str, Any]]:
415416
"""List available output devices with indices."""
416-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
417+
import sounddevice as sd
417418

418419
devices = sd.query_devices()
419420
result: list[dict[str, Any]] = []
@@ -424,14 +425,14 @@ def list_output_devices(self) -> list[dict[str, Any]]:
424425

425426
def default_input_device(self) -> Optional[int]:
426427
"""Return the default input device index (or None)."""
427-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
428+
import sounddevice as sd
428429

429430
dev = sd.default.device
430431
return dev[0] if isinstance(dev, (list, tuple)) else None
431432

432433
def default_output_device(self) -> Optional[int]:
433434
"""Return the default output device index (or None)."""
434-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
435+
import sounddevice as sd
435436

436437
dev = sd.default.device
437438
return dev[1] if isinstance(dev, (list, tuple)) else None
@@ -471,7 +472,7 @@ def open_input(
471472
Returns:
472473
InputCapture: Holder with `source`, `apm`, and `aclose()`.
473474
"""
474-
import sounddevice as sd # type: ignore[import-not-found, import-untyped]
475+
import sounddevice as sd
475476

476477
loop = self._loop
477478
source = AudioSource(self._in_sr, self._channels, loop=loop)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ exclude = "(build|setup\\.py|livekit-rtc/rust-sdks.*)"
7171
namespace_packages = true
7272
explicit_package_bases = true
7373
mypy_path = "livekit-protocol:livekit-api:livekit-rtc"
74-
strict = false # TODO re-enable strict checking
74+
strict = true
7575
disallow_any_generics = false
7676
plugins = ["pydantic.mypy"]

0 commit comments

Comments
 (0)