48
48
Body ,
49
49
Omit ,
50
50
Query ,
51
- ModelT ,
52
51
Headers ,
53
52
Timeout ,
54
53
NotGiven ,
61
60
HttpxSendArgs ,
62
61
AsyncTransport ,
63
62
RequestOptions ,
64
- UnknownResponse ,
65
63
ModelBuilderProtocol ,
66
64
BinaryResponseContent ,
67
65
)
@@ -142,7 +140,7 @@ def __init__(
142
140
self .params = params
143
141
144
142
145
- class BasePage (GenericModel , Generic [ModelT ]):
143
+ class BasePage (GenericModel , Generic [_T ]):
146
144
"""
147
145
Defines the core interface for pagination.
148
146
@@ -155,7 +153,7 @@ class BasePage(GenericModel, Generic[ModelT]):
155
153
"""
156
154
157
155
_options : FinalRequestOptions = PrivateAttr ()
158
- _model : Type [ModelT ] = PrivateAttr ()
156
+ _model : Type [_T ] = PrivateAttr ()
159
157
160
158
def has_next_page (self ) -> bool :
161
159
items = self ._get_page_items ()
@@ -166,7 +164,7 @@ def has_next_page(self) -> bool:
166
164
def next_page_info (self ) -> Optional [PageInfo ]:
167
165
...
168
166
169
- def _get_page_items (self ) -> Iterable [ModelT ]: # type: ignore[empty-body]
167
+ def _get_page_items (self ) -> Iterable [_T ]: # type: ignore[empty-body]
170
168
...
171
169
172
170
def _params_from_url (self , url : URL ) -> httpx .QueryParams :
@@ -191,13 +189,13 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions:
191
189
raise ValueError ("Unexpected PageInfo state" )
192
190
193
191
194
- class BaseSyncPage (BasePage [ModelT ], Generic [ModelT ]):
192
+ class BaseSyncPage (BasePage [_T ], Generic [_T ]):
195
193
_client : SyncAPIClient = pydantic .PrivateAttr ()
196
194
197
195
def _set_private_attributes (
198
196
self ,
199
197
client : SyncAPIClient ,
200
- model : Type [ModelT ],
198
+ model : Type [_T ],
201
199
options : FinalRequestOptions ,
202
200
) -> None :
203
201
self ._model = model
@@ -212,7 +210,7 @@ def _set_private_attributes(
212
210
# methods should continue to work as expected as there is an alternative method
213
211
# to cast a model to a dictionary, model.dict(), which is used internally
214
212
# by pydantic.
215
- def __iter__ (self ) -> Iterator [ModelT ]: # type: ignore
213
+ def __iter__ (self ) -> Iterator [_T ]: # type: ignore
216
214
for page in self .iter_pages ():
217
215
for item in page ._get_page_items ():
218
216
yield item
@@ -237,13 +235,13 @@ def get_next_page(self: SyncPageT) -> SyncPageT:
237
235
return self ._client ._request_api_list (self ._model , page = self .__class__ , options = options )
238
236
239
237
240
- class AsyncPaginator (Generic [ModelT , AsyncPageT ]):
238
+ class AsyncPaginator (Generic [_T , AsyncPageT ]):
241
239
def __init__ (
242
240
self ,
243
241
client : AsyncAPIClient ,
244
242
options : FinalRequestOptions ,
245
243
page_cls : Type [AsyncPageT ],
246
- model : Type [ModelT ],
244
+ model : Type [_T ],
247
245
) -> None :
248
246
self ._model = model
249
247
self ._client = client
@@ -266,7 +264,7 @@ def _parser(resp: AsyncPageT) -> AsyncPageT:
266
264
267
265
return await self ._client .request (self ._page_cls , self ._options )
268
266
269
- async def __aiter__ (self ) -> AsyncIterator [ModelT ]:
267
+ async def __aiter__ (self ) -> AsyncIterator [_T ]:
270
268
# https://github.com/microsoft/pyright/issues/3464
271
269
page = cast (
272
270
AsyncPageT ,
@@ -276,20 +274,20 @@ async def __aiter__(self) -> AsyncIterator[ModelT]:
276
274
yield item
277
275
278
276
279
- class BaseAsyncPage (BasePage [ModelT ], Generic [ModelT ]):
277
+ class BaseAsyncPage (BasePage [_T ], Generic [_T ]):
280
278
_client : AsyncAPIClient = pydantic .PrivateAttr ()
281
279
282
280
def _set_private_attributes (
283
281
self ,
284
- model : Type [ModelT ],
282
+ model : Type [_T ],
285
283
client : AsyncAPIClient ,
286
284
options : FinalRequestOptions ,
287
285
) -> None :
288
286
self ._model = model
289
287
self ._client = client
290
288
self ._options = options
291
289
292
- async def __aiter__ (self ) -> AsyncIterator [ModelT ]:
290
+ async def __aiter__ (self ) -> AsyncIterator [_T ]:
293
291
async for page in self .iter_pages ():
294
292
for item in page ._get_page_items ():
295
293
yield item
@@ -528,7 +526,7 @@ def _process_response_data(
528
526
if data is None :
529
527
return cast (ResponseT , None )
530
528
531
- if cast_to is UnknownResponse :
529
+ if cast_to is object :
532
530
return cast (ResponseT , data )
533
531
534
532
try :
@@ -970,7 +968,7 @@ def _retry_request(
970
968
971
969
def _request_api_list (
972
970
self ,
973
- model : Type [ModelT ],
971
+ model : Type [object ],
974
972
page : Type [SyncPageT ],
975
973
options : FinalRequestOptions ,
976
974
) -> SyncPageT :
@@ -1132,7 +1130,7 @@ def get_api_list(
1132
1130
self ,
1133
1131
path : str ,
1134
1132
* ,
1135
- model : Type [ModelT ],
1133
+ model : Type [object ],
1136
1134
page : Type [SyncPageT ],
1137
1135
body : Body | None = None ,
1138
1136
options : RequestOptions = {},
@@ -1434,10 +1432,10 @@ async def _retry_request(
1434
1432
1435
1433
def _request_api_list (
1436
1434
self ,
1437
- model : Type [ModelT ],
1435
+ model : Type [_T ],
1438
1436
page : Type [AsyncPageT ],
1439
1437
options : FinalRequestOptions ,
1440
- ) -> AsyncPaginator [ModelT , AsyncPageT ]:
1438
+ ) -> AsyncPaginator [_T , AsyncPageT ]:
1441
1439
return AsyncPaginator (client = self , options = options , page_cls = page , model = model )
1442
1440
1443
1441
@overload
@@ -1584,13 +1582,12 @@ def get_api_list(
1584
1582
self ,
1585
1583
path : str ,
1586
1584
* ,
1587
- # TODO: support paginating `str`
1588
- model : Type [ModelT ],
1585
+ model : Type [_T ],
1589
1586
page : Type [AsyncPageT ],
1590
1587
body : Body | None = None ,
1591
1588
options : RequestOptions = {},
1592
1589
method : str = "get" ,
1593
- ) -> AsyncPaginator [ModelT , AsyncPageT ]:
1590
+ ) -> AsyncPaginator [_T , AsyncPageT ]:
1594
1591
opts = FinalRequestOptions .construct (method = method , url = path , json_data = body , ** options )
1595
1592
return self ._request_api_list (model , page , opts )
1596
1593
0 commit comments