Skip to content

Commit 873f639

Browse files
author
Shubham
committed
Use typing.Union to avoid build failures in Python version < 3.10
1 parent 0fc7774 commit 873f639

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

objectbox/sync.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ctypes
2+
import typing
23
from enum import Enum, auto, IntEnum
34

45
import objectbox.c as c
@@ -247,7 +248,7 @@ class SyncCode(IntEnum):
247248
class SyncChange:
248249
"""Sync incoming data event."""
249250

250-
def __init__(self, entity_id: int, puts: list[int], removals: list[int]):
251+
def __init__(self, entity_id: int, puts: typing.List[int], removals: typing.List[int]):
251252
"""Creates a SyncChange event.
252253
253254
Args:
@@ -319,7 +320,7 @@ def on_error(self, sync_error_code: int):
319320

320321
class SyncChangeListener:
321322

322-
def on_change(self, sync_changes: list[SyncChange]):
323+
def on_change(self, sync_changes: typing.List[SyncChange]):
323324
"""Called when incoming data changes are received from the server.
324325
325326
Args:
@@ -334,8 +335,8 @@ class SyncClient:
334335
Use through the Sync class factory methods.
335336
"""
336337

337-
def __init__(self, store: Store, server_urls: list[str],
338-
filter_variables: dict[str, str] | None = None):
338+
def __init__(self, store: Store, server_urls: typing.List[str],
339+
filter_variables: typing.Optional[typing.Dict[str, str]] = None):
339340
"""Creates a Sync client associated with the given store and options.
340341
341342
This does not initiate any connection attempts yet: call start() to do so.
@@ -406,7 +407,7 @@ def set_credentials(self, credentials: SyncCredentials):
406407
credentials.secret,
407408
len(credentials.secret))
408409

409-
def set_multiple_credentials(self, credentials_list: list[SyncCredentials]):
410+
def set_multiple_credentials(self, credentials_list: typing.List[SyncCredentials]):
410411
"""Like set_credentials, but accepts multiple credentials.
411412
412413
However, does **not** support SyncCredentials.none().
@@ -644,7 +645,7 @@ def set_change_listener(self, change_listener: SyncChangeListener):
644645

645646
def c_change_callback(arg, sync_change_array_ptr):
646647
sync_change_array = ctypes.cast(sync_change_array_ptr, ctypes.POINTER(OBX_sync_change_array)).contents
647-
changes: list[SyncChange] = []
648+
changes: typing.List[SyncChange] = []
648649
for i in range(sync_change_array.count):
649650
c_sync_change: c.OBX_sync_change = sync_change_array.list[i]
650651
puts = []
@@ -749,7 +750,7 @@ class Sync:
749750
750751
Start a client using Sync.client() and connect to a remote server.
751752
"""
752-
__sync_clients: dict[Store, SyncClient] = {}
753+
__sync_clients: typing.Dict[Store, SyncClient] = {}
753754

754755
@staticmethod
755756
def is_available() -> bool:
@@ -761,7 +762,7 @@ def client(
761762
store: Store,
762763
server_url: str,
763764
credential: SyncCredentials,
764-
filter_variables: dict[str, str] | None = None
765+
filter_variables: typing.Optional[typing.Dict[str, str]] = None
765766
) -> SyncClient:
766767
"""Creates a Sync client associated with the given store and configures it
767768
with the given options.
@@ -793,8 +794,8 @@ def client(
793794
def client_multi_creds(
794795
store: Store,
795796
server_url: str,
796-
credentials_list: list[SyncCredentials],
797-
filter_variables: dict[str, str] | None = None
797+
credentials_list: typing.List[SyncCredentials],
798+
filter_variables: typing.Optional[typing.Dict[str, str]] = None
798799
) -> SyncClient:
799800
"""Like client(), but accepts a list of credentials.
800801
@@ -817,9 +818,9 @@ def client_multi_creds(
817818
@staticmethod
818819
def client_multi_urls(
819820
store: Store,
820-
server_urls: list[str],
821+
server_urls: typing.List[str],
821822
credential: SyncCredentials,
822-
filter_variables: dict[str, str] | None = None
823+
filter_variables: typing.Optional[typing.Dict[str, str]] = None
823824
) -> SyncClient:
824825
"""Like client(), but accepts a list of URLs to work with multiple servers.
825826
@@ -839,9 +840,9 @@ def client_multi_urls(
839840
@staticmethod
840841
def client_multi_creds_multi_urls(
841842
store: Store,
842-
server_urls: list[str],
843-
credentials_list: list[SyncCredentials],
844-
filter_variables: dict[str, str] | None = None
843+
server_urls: typing.List[str],
844+
credentials_list: typing.List[SyncCredentials],
845+
filter_variables: typing.Optional[typing.Dict[str, str]] = None
845846
) -> SyncClient:
846847
"""Like client(), but accepts a list of credentials and a list of URLs to
847848
work with multiple servers.

tests/test_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Callable
1+
from typing import Callable, Optional
22

33
import pytest
44

@@ -101,7 +101,7 @@ def test_client_closed_when_store_closed(test_store, sync_client):
101101

102102

103103
@pytest.mark.sync
104-
def assert_raises_value_error(fn: Callable[[], object | None], message: str | None = None):
104+
def assert_raises_value_error(fn: Callable[[], Optional[object]], message: Optional[str] = None):
105105
with pytest.raises(ValueError, match=message):
106106
fn()
107107

0 commit comments

Comments
 (0)