Skip to content

Commit dd645de

Browse files
chore(internal): base client updates
1 parent 9a19507 commit dd645de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/finch/_base_client.py

+25
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class PageInfo:
120120

121121
url: URL | NotGiven
122122
params: Query | NotGiven
123+
json: Body | NotGiven
123124

124125
@overload
125126
def __init__(
@@ -135,19 +136,30 @@ def __init__(
135136
params: Query,
136137
) -> None: ...
137138

139+
@overload
140+
def __init__(
141+
self,
142+
*,
143+
json: Body,
144+
) -> None: ...
145+
138146
def __init__(
139147
self,
140148
*,
141149
url: URL | NotGiven = NOT_GIVEN,
150+
json: Body | NotGiven = NOT_GIVEN,
142151
params: Query | NotGiven = NOT_GIVEN,
143152
) -> None:
144153
self.url = url
154+
self.json = json
145155
self.params = params
146156

147157
@override
148158
def __repr__(self) -> str:
149159
if self.url:
150160
return f"{self.__class__.__name__}(url={self.url})"
161+
if self.json:
162+
return f"{self.__class__.__name__}(json={self.json})"
151163
return f"{self.__class__.__name__}(params={self.params})"
152164

153165

@@ -196,6 +208,19 @@ def _info_to_options(self, info: PageInfo) -> FinalRequestOptions:
196208
options.url = str(url)
197209
return options
198210

211+
if not isinstance(info.json, NotGiven):
212+
if not is_mapping(info.json):
213+
raise TypeError("Pagination is only supported with mappings")
214+
215+
if not options.json_data:
216+
options.json_data = {**info.json}
217+
else:
218+
if not is_mapping(options.json_data):
219+
raise TypeError("Pagination is only supported with mappings")
220+
221+
options.json_data = {**options.json_data, **info.json}
222+
return options
223+
199224
raise ValueError("Unexpected PageInfo state")
200225

201226

0 commit comments

Comments
 (0)