2020"""
2121
2222import asyncio
23+ from collections .abc import Awaitable , Generator
2324import copy
2425from dataclasses import dataclass
2526import datetime
@@ -201,7 +202,7 @@ def __aiter__(self) -> 'HttpResponse':
201202 self .segment_iterator = self .async_segments ()
202203 return self
203204
204- async def __anext__ (self ):
205+ async def __anext__ (self ) -> Any :
205206 try :
206207 return await self .segment_iterator .__anext__ ()
207208 except StopIteration :
@@ -213,7 +214,7 @@ def json(self) -> Any:
213214 return ''
214215 return json .loads (self .response_stream [0 ])
215216
216- def segments (self ):
217+ def segments (self ) -> Generator [ Any , None , None ] :
217218 if isinstance (self .response_stream , list ):
218219 # list of objects retrieved from replay or from non-streaming API.
219220 for chunk in self .response_stream :
@@ -222,7 +223,7 @@ def segments(self):
222223 yield from []
223224 else :
224225 # Iterator of objects retrieved from the API.
225- for chunk in self .response_stream .iter_lines ():
226+ for chunk in self .response_stream .iter_lines (): # type: ignore[union-attr]
226227 if chunk :
227228 # In streaming mode, the chunk of JSON is prefixed with "data:" which
228229 # we must strip before parsing.
@@ -256,7 +257,7 @@ async def async_segments(self) -> AsyncIterator[Any]:
256257 else :
257258 raise ValueError ('Error parsing streaming response.' )
258259
259- def byte_segments (self ):
260+ def byte_segments (self ) -> Generator [ Union [ bytes , Any ], None , None ] :
260261 if isinstance (self .byte_stream , list ):
261262 # list of objects retrieved from replay or from non-streaming API.
262263 yield from self .byte_stream
@@ -267,7 +268,7 @@ def byte_segments(self):
267268 'Byte segments are not supported for streaming responses.'
268269 )
269270
270- def _copy_to_dict (self , response_payload : dict [str , object ]):
271+ def _copy_to_dict (self , response_payload : dict [str , object ]) -> None :
271272 # Cannot pickle 'generator' object.
272273 delattr (self , 'segment_iterator' )
273274 for attribute in dir (self ):
@@ -521,11 +522,11 @@ def _access_token(self) -> str:
521522 _refresh_auth (self ._credentials )
522523 if not self ._credentials .token :
523524 raise RuntimeError ('Could not resolve API token from the environment' )
524- return self ._credentials .token
525+ return self ._credentials .token # type: ignore[no-any-return]
525526 else :
526527 raise RuntimeError ('Could not resolve API token from the environment' )
527528
528- async def _async_access_token (self ) -> str :
529+ async def _async_access_token (self ) -> Union [ str , Any ] :
529530 """Retrieves the access token for the credentials asynchronously."""
530531 if not self ._credentials :
531532 async with self ._auth_lock :
@@ -675,7 +676,7 @@ def _request(
675676
676677 async def _async_request (
677678 self , http_request : HttpRequest , stream : bool = False
678- ):
679+ ) -> HttpResponse :
679680 data : Optional [Union [str , bytes ]] = None
680681 if self .vertexai and not self .api_key :
681682 http_request .headers ['Authorization' ] = (
@@ -735,7 +736,7 @@ def request(
735736 path : str ,
736737 request_dict : dict [str , object ],
737738 http_options : Optional [HttpOptionsOrDict ] = None ,
738- ):
739+ ) -> Union [ BaseResponse , Any ] :
739740 http_request = self ._build_request (
740741 http_method , path , request_dict , http_options
741742 )
@@ -753,7 +754,7 @@ def request_streamed(
753754 path : str ,
754755 request_dict : dict [str , object ],
755756 http_options : Optional [HttpOptionsOrDict ] = None ,
756- ):
757+ ) -> Generator [ Any , None , None ] :
757758 http_request = self ._build_request (
758759 http_method , path , request_dict , http_options
759760 )
@@ -768,7 +769,7 @@ async def async_request(
768769 path : str ,
769770 request_dict : dict [str , object ],
770771 http_options : Optional [HttpOptionsOrDict ] = None ,
771- ) -> dict [ str , object ]:
772+ ) -> Union [ BaseResponse , Any ]:
772773 http_request = self ._build_request (
773774 http_method , path , request_dict , http_options
774775 )
@@ -785,18 +786,18 @@ async def async_request_streamed(
785786 path : str ,
786787 request_dict : dict [str , object ],
787788 http_options : Optional [HttpOptionsOrDict ] = None ,
788- ):
789+ ) -> Any :
789790 http_request = self ._build_request (
790791 http_method , path , request_dict , http_options
791792 )
792793
793794 response = await self ._async_request (http_request = http_request , stream = True )
794795
795- async def async_generator ():
796+ async def async_generator (): # type: ignore[no-untyped-def]
796797 async for chunk in response :
797798 yield chunk
798799
799- return async_generator ()
800+ return async_generator () # type: ignore[no-untyped-call]
800801
801802 def upload_file (
802803 self ,
@@ -977,7 +978,7 @@ async def async_upload_file(
977978
978979 async def _async_upload_fd (
979980 self ,
980- file : Union [io .IOBase , anyio .AsyncFile ],
981+ file : Union [io .IOBase , anyio .AsyncFile [ Any ] ],
981982 upload_url : str ,
982983 upload_size : int ,
983984 * ,
@@ -1093,5 +1094,5 @@ async def async_download_file(
10931094 # This method does nothing in the real api client. It is used in the
10941095 # replay_api_client to verify the response from the SDK method matches the
10951096 # recorded response.
1096- def _verify_response (self , response_model : _common .BaseModel ):
1097+ def _verify_response (self , response_model : _common .BaseModel ) -> None :
10971098 pass
0 commit comments