100
100
_AsyncStreamT = TypeVar ("_AsyncStreamT" , bound = AsyncStream [Any ])
101
101
102
102
if TYPE_CHECKING :
103
- from httpx ._config import DEFAULT_TIMEOUT_CONFIG as HTTPX_DEFAULT_TIMEOUT
103
+ from httpx ._config import (
104
+ DEFAULT_TIMEOUT_CONFIG , # pyright: ignore[reportPrivateImportUsage]
105
+ )
106
+
107
+ HTTPX_DEFAULT_TIMEOUT = DEFAULT_TIMEOUT_CONFIG
104
108
else :
105
109
try :
106
110
from httpx ._config import DEFAULT_TIMEOUT_CONFIG as HTTPX_DEFAULT_TIMEOUT
@@ -117,6 +121,7 @@ class PageInfo:
117
121
118
122
url : URL | NotGiven
119
123
params : Query | NotGiven
124
+ json : Body | NotGiven
120
125
121
126
@overload
122
127
def __init__ (
@@ -132,19 +137,30 @@ def __init__(
132
137
params : Query ,
133
138
) -> None : ...
134
139
140
+ @overload
141
+ def __init__ (
142
+ self ,
143
+ * ,
144
+ json : Body ,
145
+ ) -> None : ...
146
+
135
147
def __init__ (
136
148
self ,
137
149
* ,
138
150
url : URL | NotGiven = NOT_GIVEN ,
151
+ json : Body | NotGiven = NOT_GIVEN ,
139
152
params : Query | NotGiven = NOT_GIVEN ,
140
153
) -> None :
141
154
self .url = url
155
+ self .json = json
142
156
self .params = params
143
157
144
158
@override
145
159
def __repr__ (self ) -> str :
146
160
if self .url :
147
161
return f"{ self .__class__ .__name__ } (url={ self .url } )"
162
+ if self .json :
163
+ return f"{ self .__class__ .__name__ } (json={ self .json } )"
148
164
return f"{ self .__class__ .__name__ } (params={ self .params } )"
149
165
150
166
@@ -193,6 +209,19 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions:
193
209
options .url = str (url )
194
210
return options
195
211
212
+ if not isinstance (info .json , NotGiven ):
213
+ if not is_mapping (info .json ):
214
+ raise TypeError ("Pagination is only supported with mappings" )
215
+
216
+ if not options .json_data :
217
+ options .json_data = {** info .json }
218
+ else :
219
+ if not is_mapping (options .json_data ):
220
+ raise TypeError ("Pagination is only supported with mappings" )
221
+
222
+ options .json_data = {** options .json_data , ** info .json }
223
+ return options
224
+
196
225
raise ValueError ("Unexpected PageInfo state" )
197
226
198
227
0 commit comments