Skip to content

Commit c1ccaf2

Browse files
committed
chore(internal): add overloads to client.get for streaming (#19)
1 parent 8f21f60 commit c1ccaf2

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

src/finch/_base_client.py

+76-2
Original file line numberDiff line numberDiff line change
@@ -820,17 +820,54 @@ def _request_api_list(
820820
)
821821
return resp
822822

823+
@overload
823824
def get(
824825
self,
825826
path: str,
826827
*,
827828
cast_to: Type[ResponseT],
828829
options: RequestOptions = {},
830+
stream: Literal[False] = False,
829831
) -> ResponseT:
832+
...
833+
834+
@overload
835+
def get(
836+
self,
837+
path: str,
838+
*,
839+
cast_to: Type[ResponseT],
840+
options: RequestOptions = {},
841+
stream: Literal[True],
842+
stream_cls: type[_StreamT],
843+
) -> _StreamT:
844+
...
845+
846+
@overload
847+
def get(
848+
self,
849+
path: str,
850+
*,
851+
cast_to: Type[ResponseT],
852+
options: RequestOptions = {},
853+
stream: bool,
854+
stream_cls: type[_StreamT] | None = None,
855+
) -> ResponseT | _StreamT:
856+
...
857+
858+
def get(
859+
self,
860+
path: str,
861+
*,
862+
cast_to: Type[ResponseT],
863+
options: RequestOptions = {},
864+
stream: bool = False,
865+
stream_cls: type[_StreamT] | None = None,
866+
) -> ResponseT | _StreamT:
830867
opts = FinalRequestOptions.construct(method="get", url=path, **options)
831868
# cast is required because mypy complains about returning Any even though
832869
# it understands the type variables
833-
return cast(ResponseT, self.request(cast_to, opts, stream=False))
870+
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
834871

835872
@overload
836873
def post(
@@ -1117,15 +1154,52 @@ def _request_api_list(
11171154
) -> AsyncPaginator[ModelT, AsyncPageT]:
11181155
return AsyncPaginator(client=self, options=options, page_cls=page, model=model)
11191156

1157+
@overload
11201158
async def get(
11211159
self,
11221160
path: str,
11231161
*,
11241162
cast_to: Type[ResponseT],
11251163
options: RequestOptions = {},
1164+
stream: Literal[False] = False,
11261165
) -> ResponseT:
1166+
...
1167+
1168+
@overload
1169+
async def get(
1170+
self,
1171+
path: str,
1172+
*,
1173+
cast_to: Type[ResponseT],
1174+
options: RequestOptions = {},
1175+
stream: Literal[True],
1176+
stream_cls: type[_AsyncStreamT],
1177+
) -> _AsyncStreamT:
1178+
...
1179+
1180+
@overload
1181+
async def get(
1182+
self,
1183+
path: str,
1184+
*,
1185+
cast_to: Type[ResponseT],
1186+
options: RequestOptions = {},
1187+
stream: bool,
1188+
stream_cls: type[_AsyncStreamT] | None = None,
1189+
) -> ResponseT | _AsyncStreamT:
1190+
...
1191+
1192+
async def get(
1193+
self,
1194+
path: str,
1195+
*,
1196+
cast_to: Type[ResponseT],
1197+
options: RequestOptions = {},
1198+
stream: bool = False,
1199+
stream_cls: type[_AsyncStreamT] | None = None,
1200+
) -> ResponseT | _AsyncStreamT:
11271201
opts = FinalRequestOptions.construct(method="get", url=path, **options)
1128-
return await self.request(cast_to, opts)
1202+
return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
11291203

11301204
@overload
11311205
async def post(

0 commit comments

Comments
 (0)