@@ -17,18 +17,29 @@ class JSONLDecoder(Generic[_T]):
17
17
into a given type.
18
18
"""
19
19
20
- http_response : httpx .Response | None
20
+ http_response : httpx .Response
21
21
"""The HTTP response this decoder was constructed from"""
22
22
23
23
def __init__ (
24
- self , * , raw_iterator : Iterator [bytes ], line_type : type [_T ], http_response : httpx .Response | None
24
+ self ,
25
+ * ,
26
+ raw_iterator : Iterator [bytes ],
27
+ line_type : type [_T ],
28
+ http_response : httpx .Response ,
25
29
) -> None :
26
30
super ().__init__ ()
27
31
self .http_response = http_response
28
32
self ._raw_iterator = raw_iterator
29
33
self ._line_type = line_type
30
34
self ._iterator = self .__decode__ ()
31
35
36
+ def close (self ) -> None :
37
+ """Close the response body stream.
38
+
39
+ This is called automatically if you consume the entire stream.
40
+ """
41
+ self .http_response .close ()
42
+
32
43
def __decode__ (self ) -> Iterator [_T ]:
33
44
buf = b""
34
45
for chunk in self ._raw_iterator :
@@ -63,17 +74,28 @@ class AsyncJSONLDecoder(Generic[_T]):
63
74
into a given type.
64
75
"""
65
76
66
- http_response : httpx .Response | None
77
+ http_response : httpx .Response
67
78
68
79
def __init__ (
69
- self , * , raw_iterator : AsyncIterator [bytes ], line_type : type [_T ], http_response : httpx .Response | None
80
+ self ,
81
+ * ,
82
+ raw_iterator : AsyncIterator [bytes ],
83
+ line_type : type [_T ],
84
+ http_response : httpx .Response ,
70
85
) -> None :
71
86
super ().__init__ ()
72
87
self .http_response = http_response
73
88
self ._raw_iterator = raw_iterator
74
89
self ._line_type = line_type
75
90
self ._iterator = self .__decode__ ()
76
91
92
+ async def close (self ) -> None :
93
+ """Close the response body stream.
94
+
95
+ This is called automatically if you consume the entire stream.
96
+ """
97
+ await self .http_response .aclose ()
98
+
77
99
async def __decode__ (self ) -> AsyncIterator [_T ]:
78
100
buf = b""
79
101
async for chunk in self ._raw_iterator :
0 commit comments