Skip to content

Commit 8071677

Browse files
solves nitpick comments
1 parent ef2bae4 commit 8071677

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/repositories/interface.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
wait_fixed,
1010
retry,
1111
)
12-
from pydantic import BaseModel
12+
from pydantic import BaseModel, ValidationError
1313
from pymongo.errors import PyMongoError
1414
from pymongo.server_api import ServerApi
1515
from motor.motor_asyncio import AsyncIOMotorClient
@@ -221,6 +221,7 @@ async def insert(self, data: dict):
221221
raise HTTPException(status_code=422, detail=str(e))
222222
result = await collection.insert_one(data)
223223
return str(result.inserted_id)
224+
224225
@repository_exception_handler
225226
async def update_by_id(self, data: dict, *, data_id: str):
226227
collection = self.get_collection()

src/utils.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@
55
from typing import Annotated, NoReturn, Any
66
import numpy as np
77

8-
from pydantic import BeforeValidator, PlainSerializer
8+
from pydantic import PlainSerializer
99
from starlette.datastructures import Headers, MutableHeaders
1010
from starlette.types import ASGIApp, Message, Receive, Scope, Send
1111

1212

13-
def to_python_primitive(v):
13+
def to_python_primitive(v: Any) -> Any:
14+
"""
15+
Convert complex types to Python primitives.
16+
17+
Args:
18+
v: Any value, particularly those with a 'source' attribute
19+
containing numpy arrays or generic types.
20+
21+
Returns:
22+
The primitive representation of the input value.
23+
"""
1424
if hasattr(v, "source"):
1525
if isinstance(v.source, np.ndarray):
1626
return v.source.tolist()
@@ -19,13 +29,11 @@ def to_python_primitive(v):
1929
return v.source.item()
2030

2131
return str(v.source)
22-
2332
return str(v)
2433

2534

2635
AnyToPrimitive = Annotated[
2736
Any,
28-
BeforeValidator(lambda v: v),
2937
PlainSerializer(to_python_primitive),
3038
]
3139

@@ -145,7 +153,6 @@ async def send_with_gzip(self, message: Message) -> None:
145153
self.gzip_buffer.truncate()
146154

147155
await self.send(message)
148-
return
149156

150157

151158
async def unattached_send(message: Message) -> NoReturn:

0 commit comments

Comments
 (0)