Skip to content

Commit 1cd09d3

Browse files
committed
Adjusting typing information - The Json serializer must be able to deal with sequences
1 parent afacf87 commit 1cd09d3

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

arangoasync/collection.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
RequestHeaders,
3939
)
4040

41-
T = TypeVar("T")
42-
U = TypeVar("U")
43-
V = TypeVar("V")
41+
T = TypeVar("T") # Serializer type
42+
U = TypeVar("U") # Deserializer loads
43+
V = TypeVar("V") # Deserializer loads_many
4444

4545

4646
class Collection(Generic[T, U, V]):
@@ -892,7 +892,7 @@ def response_handler(resp: Response) -> bool | Json:
892892

893893
async def get_many(
894894
self,
895-
documents: Sequence[str | Json],
895+
documents: Sequence[str | T],
896896
allow_dirty_read: Optional[bool] = None,
897897
ignore_revs: Optional[bool] = None,
898898
) -> Result[V]:
@@ -925,14 +925,17 @@ async def get_many(
925925

926926
headers: RequestHeaders = {}
927927
if allow_dirty_read is not None:
928-
headers["x-arango-allow-dirty-read"] = allow_dirty_read
928+
if allow_dirty_read is True:
929+
headers["x-arango-allow-dirty-read"] = "true"
930+
else:
931+
headers["x-arango-allow-dirty-read"] = "false"
929932

930933
request = Request(
931934
method=Method.PUT,
932935
endpoint=f"/_api/document/{self.name}",
933936
params=params,
934937
headers=headers,
935-
data=self.serializer.dumps(documents),
938+
data=self._doc_serializer.dumps(documents),
936939
)
937940

938941
def response_handler(resp: Response) -> V:

arangoasync/serialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Serializer(ABC, Generic[T]): # pragma: no cover
2626
"""
2727

2828
@abstractmethod
29-
def dumps(self, data: str | bool | T | Sequence[T | str]) -> str:
29+
def dumps(self, data: T | Sequence[T | str]) -> str:
3030
"""Serialize any generic data.
3131
3232
Args:
@@ -87,7 +87,7 @@ def loads_many(self, data: bytes) -> U:
8787
class JsonSerializer(Serializer[Json]):
8888
"""JSON serializer."""
8989

90-
def dumps(self, data: T) -> str:
90+
def dumps(self, data: Json | Sequence[str | Json]) -> str:
9191
try:
9292
return json.dumps(data, separators=(",", ":"))
9393
except Exception as e:

0 commit comments

Comments
 (0)