Skip to content

Commit 30b06d9

Browse files
committed
more typing
1 parent 38f397c commit 30b06d9

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.pyright]
2+
typeCheckingMode = "basic"

thingsdb/client/buildin.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def query(
1919
**kwargs: Any) -> asyncio.Future[Any]:
2020
...
2121

22-
async def collection_info(self, collection: int | str) -> dict:
22+
async def collection_info(self, collection: int | str) -> dict[str, Any]:
2323
"""Returns information about a specific collection.
2424
2525
This function requires QUERY privileges on the requested collection,
@@ -32,7 +32,7 @@ async def collection_info(self, collection: int | str) -> dict:
3232
collection=collection,
3333
scope='@t')
3434

35-
async def collections_info(self) -> list:
35+
async def collections_info(self) -> list[dict[str, Any]]:
3636
"""Returns collection information about all collections in ThingsDB.
3737
"""
3838
return await self.query('collections_info()', scope='@t')
@@ -205,10 +205,10 @@ async def has_user(self, name: str):
205205
"""
206206
return await self.query('has_user(name)', name=name, scope='@t')
207207

208-
async def module_info(self, name: str) -> dict:
208+
async def module_info(self, name: str) -> dict[str, Any]:
209209
return await self.query('module_info(name)', name=name, scope='@t')
210210

211-
async def modules_info(self) -> list:
211+
async def modules_info(self) -> list[dict[str, Any]]:
212212
return await self.query('modules_info()', scope='@t')
213213

214214
async def new_collection(self, name: str):
@@ -369,49 +369,49 @@ async def set_time_zone(self, collection: int | str, zone: str):
369369
zone=zone,
370370
scope='@t')
371371

372-
async def time_zones_info(self) -> list:
372+
async def time_zones_info(self) -> list[str]:
373373
"""Returns all available time zones in ThingsDB.
374374
375375
This function does not generate a change.
376376
"""
377377
return await self.query('time_zones_info()', scope='@t')
378378

379-
async def user_info(self, user: str | None = None) -> dict:
379+
async def user_info(self, user: str | None = None) -> dict[str, Any]:
380380
if user is None:
381381
return await self.query('user_info()', scope='@t')
382382
return await self.query('user_info(user)', user=user, scope='@t')
383383

384-
async def users_info(self) -> list:
384+
async def users_info(self) -> list[dict[str, Any]]:
385385
return await self.query('users_info()', scope='@t')
386386

387387
#
388388
# Build-in functions from the @node scope
389389
#
390390

391-
async def backup_info(self, backup_id: int, scope='@n'):
391+
async def backup_info(self, backup_id: int, scope: str = '@n'):
392392
return await self.query('backup_info(id)', id=backup_id, scope=scope)
393393

394-
async def backups_info(self, scope='@n') -> list:
394+
async def backups_info(self, scope: str = '@n') -> list[dict[str, Any]]:
395395
return await self.query('backups_info()', scope=scope)
396396

397-
async def backups_ok(self, scope='@n') -> bool:
397+
async def backups_ok(self, scope: str = '@n') -> bool:
398398
return await self.query('backups_ok()', scope=scope)
399399

400-
async def counters(self, scope='@n'):
400+
async def counters(self, scope: str = '@n'):
401401
return await self.query('counters()', scope=scope)
402402

403403
async def del_backup(
404404
self,
405405
backup_id: int,
406406
delete_files: bool = False,
407-
scope='@n'):
407+
scope: str = '@n'):
408408
return await self.query(
409409
'del_backup(id, delete_files)',
410410
id=backup_id,
411411
delete_files=delete_files,
412412
scope=scope)
413413

414-
async def has_backup(self, backup_id: int, scope='@n'):
414+
async def has_backup(self, backup_id: int, scope: str = '@n'):
415415
return await self.query('has_backup(id)', id=backup_id, scope=scope)
416416

417417
async def new_backup(
@@ -420,7 +420,7 @@ async def new_backup(
420420
start_ts: datetime.datetime | None = None,
421421
repeat: int | None = 0,
422422
max_files: int | None = 7,
423-
scope='@n'):
423+
scope: str = '@n'):
424424

425425
ts = None if start_ts is None else int(start_ts.timestamp())
426426

@@ -435,13 +435,13 @@ async def new_backup(
435435
max_files=max_files,
436436
scope=scope)
437437

438-
async def node_info(self, scope='@n') -> dict:
438+
async def node_info(self, scope: str = '@n') -> dict[str, Any]:
439439
return await self.query('node_info()', scope=scope)
440440

441-
async def nodes_info(self, scope='@n') -> list:
441+
async def nodes_info(self, scope: str = '@n') -> list[dict[str, Any]]:
442442
return await self.query('nodes_info()', scope=scope)
443443

444-
async def reset_counters(self, scope='@n') -> None:
444+
async def reset_counters(self, scope: str = '@n') -> None:
445445
"""Resets the counters for the ThingsDB node you are connected too.
446446
447447
Other nodes are not affected. This will set the started_at counter
@@ -462,7 +462,7 @@ async def restart_module(self, name: str) -> None:
462462
"""
463463
return await self.query('restart_module(name)', name=name, scope='@t')
464464

465-
async def set_log_level(self, log_level: str, scope='@n') -> None:
465+
async def set_log_level(self, log_level: str, scope: str = '@n') -> None:
466466
level = (
467467
'DEBUG',
468468
'INFO',
@@ -472,7 +472,7 @@ async def set_log_level(self, log_level: str, scope='@n') -> None:
472472
return await self.query(
473473
'set_log_level(log_level)', log_level=level, scope=scope)
474474

475-
async def shutdown(self, scope='@n') -> None:
475+
async def shutdown(self, scope: str = '@n') -> None:
476476
"""Shutdown the node in the selected scope.
477477
478478
This is a clean shutdown, allowing all other nodes (and clients) to

thingsdb/room/roombase.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import abc
22
import asyncio
33
import logging
4-
from typing import Callable, TypeVar, ParamSpec
4+
from typing import Callable, TypeVar, ParamSpec, Any, TypedDict
55
from ..client import Client
66
from ..client.protocol import Proto
77
from ..util.is_name import is_name
@@ -11,10 +11,15 @@
1111
R = TypeVar('R')
1212

1313

14+
class _TEvent(TypedDict):
15+
event: str
16+
args: list[Any]
17+
18+
1419
class RoomBase(abc.ABC):
1520

1621
def __init_subclass__(cls):
17-
cls._event_handlers = {}
22+
cls._event_handlers: dict[str, Callable[[Any], object]] = {}
1823

1924
for key, val in cls.__dict__.items():
2025
if not key.startswith('__') and \
@@ -223,7 +228,7 @@ async def _on_first_join(self):
223228
finally:
224229
fut.set_result(None)
225230

226-
def _on_join(self, _data) -> asyncio.Task | None:
231+
def _on_join(self, _data: Any) -> asyncio.Task[None] | None:
227232
if self._wait_join:
228233
# Future, the first join. Return a task so the room lock is kept
229234
# until the on_first_join is finished
@@ -240,15 +245,15 @@ def _on_join(self, _data) -> asyncio.Task | None:
240245
loop = self._client.get_event_loop()
241246
asyncio.ensure_future(self.on_join(), loop=loop)
242247

243-
def _on_stop(self, func):
248+
def _on_stop(self, func: Callable[[], None]):
244249
try:
245250
assert self._client
246251
del self._client._rooms[self._id]
247252
except KeyError:
248253
pass
249254
func()
250255

251-
def _emit_handler(self, data):
256+
def _emit_handler(self, data: _TEvent):
252257
cls = self.__class__
253258
event = data['event']
254259
try:

0 commit comments

Comments
 (0)