1
1
import abc
2
2
import dataclasses as dc
3
3
from collections .abc import Callable
4
- from typing import Any
5
4
6
5
import httpx
7
6
import pydantic
@@ -23,9 +22,9 @@ class Responses:
23
22
class ResponseEnvelopeBuilder :
24
23
def __init__ (self , typ : type [pydantic .BaseModel ]) -> None :
25
24
self ._type = typ
26
- self .fields = {}
25
+ self .fields : typing . MutableMapping [ str , typing . Any ] = {}
27
26
28
- def build (self ) -> Any :
27
+ def build (self ) -> typing . Any :
29
28
return self ._type .model_construct (** self .fields )
30
29
31
30
@@ -45,14 +44,14 @@ def supply_formal(self, name: str, type_: type) -> None:
45
44
46
45
47
46
class Body (ResponsePartHandler , PropertyAnnotation ):
48
- _parse : Callable [[... ], Any ]
47
+ _parse : Callable [[bytes ], typing . Any ]
49
48
50
49
def supply_formal (self , name : str , type_ : type ) -> None :
51
50
super ().supply_formal (name , type_ )
52
51
self ._parse = pydantic .TypeAdapter (type_ ).validate_json
53
52
54
53
def apply (self , fields : typing .MutableMapping , response : httpx .Response ) -> None :
55
- fields [self ._name ] = self ._parse (response .text )
54
+ fields [self ._name ] = self ._parse (response .content )
56
55
57
56
58
57
class Header (ResponsePartHandler , PropertyAnnotation ):
@@ -71,4 +70,4 @@ class ResponseEnvelope(abc.ABC, pydantic.BaseModel):
71
70
72
71
73
72
class DefaultEnvelope (ResponseEnvelope , typing .Generic [BodyT ]):
74
- body : typing .Annotated [BodyT , Body ]
73
+ body : typing .Annotated [BodyT , Body () ]
0 commit comments