Skip to content

Commit 03f396b

Browse files
authored
switch typing syntax (#47)
* switch typing syntax * Upd support * drop py 3.9 support * merge conflict
1 parent b15ea4c commit 03f396b

File tree

9 files changed

+78
-82
lines changed

9 files changed

+78
-82
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
max-parallel: 4
1515
matrix:
16-
python-version: ["3.9", "3.10", "3.11", "3.12"]
16+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1717
steps:
1818
- uses: actions/checkout@v4
1919

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Python connector for ThingsDB
55

6-
> This library requires Python 3.9 or higher.
6+
> This library requires Python 3.10 or higher.
77
88
---------------------------------------
99

@@ -89,8 +89,8 @@ ThingsDB.
8989
```python
9090
thingsdb.client.Client(
9191
auto_reconnect: bool = True,
92-
ssl: Optional[Union[bool, ssl.SSLContext]] = None,
93-
loop: Optional[asyncio.AbstractEventLoop] = None
92+
ssl: bool | ssl.SSLContext | None = None,
93+
loop: asyncio.AbstractEventLoop | None = None
9494
) -> Client
9595
```
9696
Initialize a ThingsDB client
@@ -119,8 +119,8 @@ Initialize a ThingsDB client
119119

120120
```python
121121
async Client().authenticate(
122-
*auth: Union[str, tuple],
123-
timeout: Optional[int] = 5
122+
*auth: str | tuple,
123+
timeout: int | None = 5
124124
) -> None
125125
```
126126

@@ -166,7 +166,7 @@ This is equivalent of combining [close()](#close)) and [wait_closed()](#wait_clo
166166
Client().connect(
167167
host: str,
168168
port: int = 9200,
169-
timeout: Optional[int] = 5
169+
timeout: int | None = 5
170170
) -> asyncio.Future
171171
```
172172

@@ -204,7 +204,7 @@ set to `None` when successful.
204204
```python
205205
Client().connect_pool(
206206
pool: list,
207-
*auth: Union[str, tuple]
207+
*auth: str | tuple
208208
) -> asyncio.Future
209209
```
210210

@@ -313,8 +313,8 @@ Can be used to check if the client is using a WebSocket connection.
313313
```python
314314
Client().query(
315315
code: str,
316-
scope: Optional[str] = None,
317-
timeout: Optional[int] = None,
316+
scope: str | None = None,
317+
timeout: int | None = None,
318318
skip_strip_code: bool = False,
319319
**kwargs: Any
320320
) -> asyncio.Future
@@ -368,7 +368,7 @@ contain the result of the ThingsDB code when successful.
368368
### reconnect
369369

370370
```python
371-
async Client().reconnect() -> Optional[Future]
371+
async Client().reconnect() -> Future | None
372372
```
373373

374374
Re-connect to ThingsDB.
@@ -384,9 +384,9 @@ possible but not required.
384384
```python
385385
Client().run(
386386
procedure: str,
387-
*args: Optional[Any],
388-
scope: Optional[str] = None,
389-
timeout: Optional[int] = None,
387+
*args: Any,
388+
scope: str | None = None,
389+
timeout: int | None = None,
390390
**kwargs: Any
391391
) -> asyncio.Future
392392
```
@@ -547,7 +547,7 @@ Property | Description
547547
### join
548548

549549
```python
550-
Room().join(client: Client, wait: Optional[float] = 60.0) -> None
550+
Room().join(client: Client, wait: float | None = 60.0) -> None
551551
```
552552

553553
Joins the room.
@@ -572,7 +572,7 @@ Leave the room. If the room is not found, a `LookupError` will be raised.
572572
### emit
573573

574574
```python
575-
Room().emit(event: str, *args: Optional[Any],) -> asyncio.Future
575+
Room().emit(event: str, *args: Any) -> asyncio.Future
576576
```
577577

578578
Emit an event to a room.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343

4444
# Specify the Python versions you support here. In particular, ensure
4545
# that you indicate whether you support Python 2, Python 3 or both.
46-
'Programming Language :: Python :: 3.9',
4746
'Programming Language :: Python :: 3.10',
4847
'Programming Language :: Python :: 3.11',
4948
'Programming Language :: Python :: 3.12',
49+
'Programming Language :: Python :: 3.13',
5050
],
5151
install_requires=[
5252
'msgpack',

thingsdb/client/buildin.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import asyncio
22
import datetime
3-
from abc import ABC, abstractmethod
4-
from typing import Union as U
5-
from typing import Optional
3+
from abc import abstractmethod
64
from typing import Any
75

86

@@ -15,13 +13,13 @@ class Buildin:
1513
def query(
1614
self,
1715
code: str,
18-
scope: Optional[str] = None,
19-
timeout: Optional[int] = None,
16+
scope: str | None = None,
17+
timeout: int | None = None,
2018
skip_strip_code: bool = False,
2119
**kwargs: Any) -> asyncio.Future[Any]:
2220
...
2321

24-
async def collection_info(self, collection: U[int, str]) -> dict:
22+
async def collection_info(self, collection: int | str) -> dict:
2523
"""Returns information about a specific collection.
2624
2725
This function requires QUERY privileges on the requested collection,
@@ -39,7 +37,7 @@ async def collections_info(self) -> list:
3937
"""
4038
return await self.query('collections_info()', scope='@t')
4139

42-
async def del_collection(self, collection: U[int, str]):
40+
async def del_collection(self, collection: int | str):
4341
"""Delete a collection.
4442
4543
This function generates a change.
@@ -104,7 +102,7 @@ async def del_user(self, name: str):
104102
async def deploy_module(
105103
self,
106104
name: str,
107-
data: Optional[U[bytes, str]] = None):
105+
data: bytes | str | None = None):
108106
"""Deploy a module on all nodes.
109107
110108
The module must be configured first, using the new_module() function.
@@ -127,7 +125,7 @@ async def deploy_module(
127125
data=data,
128126
scope='@t')
129127

130-
async def grant(self, target: U[int, str], user: str, mask: int):
128+
async def grant(self, target: int | str, user: str, mask: int):
131129
"""Grant, collection or general, privileges to a user.
132130
133131
Access to a user is provided by setting a bit mask to either the @node,
@@ -224,7 +222,7 @@ async def new_module(
224222
self,
225223
name: str,
226224
source: str,
227-
configuration: Optional[Any] = None):
225+
configuration: Any = None):
228226
"""Creates (and configures) a new module for ThingsDB.
229227
230228
This function generates a change."""
@@ -239,7 +237,7 @@ async def new_node(
239237
self,
240238
secret: str,
241239
name: str,
242-
port: Optional[int] = 9220) -> int:
240+
port: int | None = 9220) -> int:
243241
"""Adds a new node to ThingsDB.
244242
245243
This function generates a change."""
@@ -253,7 +251,7 @@ async def new_node(
253251
async def new_token(
254252
self,
255253
user: str,
256-
expiration_time: Optional[datetime.datetime] = None,
254+
expiration_time: datetime.datetime | None = None,
257255
description: str = ''):
258256

259257
ts = None if expiration_time is None \
@@ -285,7 +283,7 @@ async def refresh_module(self, name: str):
285283

286284
async def rename_collection(
287285
self,
288-
collection: U[int, str],
286+
collection: int | str,
289287
new_name: str) -> None:
290288
return await self.query(
291289
'rename_collection(collection, new_name)',
@@ -310,14 +308,14 @@ async def rename_user(self, name: str, new_name: str) -> None:
310308
async def restore(
311309
self,
312310
filename: str,
313-
options: Optional[dict] = {}):
311+
options: dict[str, Any] | None = {}):
314312
return await self.query(
315313
'restore(filename, options)',
316314
filename=filename,
317315
options=options,
318316
scope='@t')
319317

320-
async def revoke(self, target: U[int, str], user: str, mask: int):
318+
async def revoke(self, target: int | str, user: str, mask: int):
321319
return await self.query(
322320
'revoke(target, user, mask)',
323321
target=target,
@@ -328,7 +326,7 @@ async def revoke(self, target: U[int, str], user: str, mask: int):
328326
async def set_module_conf(
329327
self,
330328
name: str,
331-
configuration: Optional[dict] = None):
329+
configuration: dict[str, Any] | None = None):
332330
return await self.query(
333331
'set_module_conf(name, configuration)',
334332
name=name,
@@ -338,22 +336,22 @@ async def set_module_conf(
338336
async def set_module_scope(
339337
self,
340338
name: str,
341-
scope: U[str, None]):
339+
scope: str | None):
342340
return await self.query(
343341
'set_module_scope(name, module_scope)',
344342
name=name,
345343
module_scope=scope,
346344
scope='@t')
347345

348346
async def set_password(self, user: str,
349-
new_password: Optional[str] = None) -> None:
347+
new_password: str | None = None) -> None:
350348
return await self.query(
351349
'set_password(user, new_password)',
352350
user=user,
353351
new_password=new_password,
354352
scope='@t')
355353

356-
async def set_time_zone(self, collection: U[int, str], zone: str):
354+
async def set_time_zone(self, collection: int | str, zone: str):
357355
"""By default each collection will be created with time zone UTC.
358356
359357
This function can be used to change the time zone for a collection. If
@@ -378,7 +376,7 @@ async def time_zones_info(self) -> list:
378376
"""
379377
return await self.query('time_zones_info()', scope='@t')
380378

381-
async def user_info(self, user: Optional[str] = None) -> dict:
379+
async def user_info(self, user: str | None = None) -> dict:
382380
if user is None:
383381
return await self.query('user_info()', scope='@t')
384382
return await self.query('user_info(user)', user=user, scope='@t')
@@ -419,9 +417,9 @@ async def has_backup(self, backup_id: int, scope='@n'):
419417
async def new_backup(
420418
self,
421419
file_template: str,
422-
start_ts: Optional[datetime.datetime] = None,
423-
repeat: Optional[int] = 0,
424-
max_files: Optional[int] = 7,
420+
start_ts: datetime.datetime | None = None,
421+
repeat: int | None = 0,
422+
max_files: int | None = 7,
425423
scope='@n'):
426424

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

0 commit comments

Comments
 (0)