5
5
from typing import Annotated , NoReturn , Any
6
6
import numpy as np
7
7
8
- from pydantic import BeforeValidator , PlainSerializer
8
+ from pydantic import PlainSerializer
9
9
from starlette .datastructures import Headers , MutableHeaders
10
10
from starlette .types import ASGIApp , Message , Receive , Scope , Send
11
11
12
12
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
+ """
14
24
if hasattr (v , "source" ):
15
25
if isinstance (v .source , np .ndarray ):
16
26
return v .source .tolist ()
@@ -19,13 +29,11 @@ def to_python_primitive(v):
19
29
return v .source .item ()
20
30
21
31
return str (v .source )
22
-
23
32
return str (v )
24
33
25
34
26
35
AnyToPrimitive = Annotated [
27
36
Any ,
28
- BeforeValidator (lambda v : v ),
29
37
PlainSerializer (to_python_primitive ),
30
38
]
31
39
@@ -145,7 +153,6 @@ async def send_with_gzip(self, message: Message) -> None:
145
153
self .gzip_buffer .truncate ()
146
154
147
155
await self .send (message )
148
- return
149
156
150
157
151
158
async def unattached_send (message : Message ) -> NoReturn :
0 commit comments