22# - [ ] Support text streaming
33# - [ ] Support file streaming
44import hashlib
5- import inspect
65import os
7- import sys
86import tempfile
97from dataclasses import dataclass
108from functools import cached_property
@@ -115,7 +113,7 @@ def _process_iterator_item(item: Any, openapi_schema: dict) -> Any:
115113 return item
116114
117115
118- def _process_output_with_schema (output : Any , openapi_schema : dict ) -> Any :
116+ def _process_output_with_schema (output : Any , openapi_schema : dict ) -> Any : # pylint: disable=too-many-branches,too-many-nested-blocks
119117 """
120118 Process output data, downloading files based on OpenAPI schema.
121119 """
@@ -143,7 +141,7 @@ def _process_output_with_schema(output: Any, openapi_schema: dict) -> Any:
143141 return output
144142
145143 # Handle object with properties
146- if output_schema .get ("type" ) == "object" and isinstance (output , dict ):
144+ if output_schema .get ("type" ) == "object" and isinstance (output , dict ): # pylint: disable=too-many-nested-blocks
147145 properties = output_schema .get ("properties" , {})
148146 result = output .copy ()
149147
@@ -179,6 +177,9 @@ def _process_output_with_schema(output: Any, openapi_schema: dict) -> Any:
179177 return output
180178
181179
180+ T = TypeVar ("T" )
181+
182+
182183class OutputIterator [T ]:
183184 """
184185 An iterator wrapper that handles both regular iteration and string conversion.
@@ -218,8 +219,7 @@ def __str__(self) -> str:
218219 """Convert to string by joining segments with empty string."""
219220 if self .is_concatenate :
220221 return "" .join ([str (segment ) for segment in self .iterator_factory ()])
221- else :
222- return str (list (self .iterator_factory ()))
222+ return str (list (self .iterator_factory ()))
223223
224224 def __await__ (self ) -> Generator [Any , None , List [T ] | str ]:
225225 """Make OutputIterator awaitable, returning appropriate result based on concatenate mode."""
@@ -231,14 +231,13 @@ async def _collect_result() -> List[T] | str:
231231 async for segment in self :
232232 segments .append (segment )
233233 return "" .join (segments )
234- else :
235- # For regular iterators, return the list of items
236- items = []
237- async for item in self :
238- items .append (item )
239- return items
234+ # For regular iterators, return the list of items
235+ items = []
236+ async for item in self :
237+ items .append (item )
238+ return items
240239
241- return _collect_result ().__await__ ()
240+ return _collect_result ().__await__ () # pylint: disable=no-member # return type confuses pylint
242241
243242
244243class URLPath (os .PathLike ):
@@ -296,6 +295,8 @@ def get_path_url(path: Any) -> str | None:
296295
297296
298297class FunctionRef (Protocol , Generic [Input , Output ]):
298+ """Represents a Replicate model, providing the model identifier and interface."""
299+
299300 name : str
300301
301302 __call__ : Callable [Input , Output ]
@@ -329,8 +330,8 @@ def output(self) -> O:
329330 return cast (
330331 O ,
331332 OutputIterator (
332- lambda : self ._prediction .output_iterator () ,
333- lambda : self ._prediction .async_output_iterator () ,
333+ self ._prediction .output_iterator ,
334+ self ._prediction .async_output_iterator ,
334335 self ._schema ,
335336 is_concatenate = is_concatenate ,
336337 ),
@@ -496,8 +497,8 @@ async def output(self) -> O:
496497 return cast (
497498 O ,
498499 OutputIterator (
499- lambda : self ._prediction .output_iterator () ,
500- lambda : self ._prediction .async_output_iterator () ,
500+ self ._prediction .output_iterator ,
501+ self ._prediction .async_output_iterator ,
501502 self ._schema ,
502503 is_concatenate = is_concatenate ,
503504 ),
@@ -685,7 +686,7 @@ def use(
685686def use (
686687 ref : str ,
687688 * ,
688- hint : Callable [Input , Output ] | None = None ,
689+ hint : Callable [Input , Output ] | None = None , # pylint: disable=unused-argument
689690 streaming : Literal [False ] = False ,
690691 use_async : Literal [False ] = False ,
691692) -> Function [Input , Output ]: ...
@@ -695,7 +696,7 @@ def use(
695696def use (
696697 ref : str ,
697698 * ,
698- hint : Callable [Input , Output ] | None = None ,
699+ hint : Callable [Input , Output ] | None = None , # pylint: disable=unused-argument
699700 streaming : Literal [True ],
700701 use_async : Literal [False ] = False ,
701702) -> Function [Input , Iterator [Output ]]: ...
@@ -705,7 +706,7 @@ def use(
705706def use (
706707 ref : str ,
707708 * ,
708- hint : Callable [Input , Output ] | None = None ,
709+ hint : Callable [Input , Output ] | None = None , # pylint: disable=unused-argument
709710 use_async : Literal [True ],
710711) -> AsyncFunction [Input , Output ]: ...
711712
@@ -714,7 +715,7 @@ def use(
714715def use (
715716 ref : str ,
716717 * ,
717- hint : Callable [Input , Output ] | None = None ,
718+ hint : Callable [Input , Output ] | None = None , # pylint: disable=unused-argument
718719 streaming : Literal [True ],
719720 use_async : Literal [True ],
720721) -> AsyncFunction [Input , AsyncIterator [Output ]]: ...
@@ -723,7 +724,7 @@ def use(
723724def use (
724725 ref : str | FunctionRef [Input , Output ],
725726 * ,
726- hint : Callable [Input , Output ] | None = None ,
727+ hint : Callable [Input , Output ] | None = None , # pylint: disable=unused-argument # required for type inference
727728 streaming : bool = False ,
728729 use_async : bool = False ,
729730) -> (
@@ -750,31 +751,3 @@ def use(
750751 return AsyncFunction (str (ref ), streaming = streaming )
751752
752753 return Function (str (ref ), streaming = streaming )
753-
754-
755- # class Model:
756- # name = "foo"
757-
758- # def __call__(self) -> str: ...
759-
760-
761- # def model() -> AsyncIterator[int]: ...
762-
763-
764- # flux = use("")
765- # flux_sync = use("", use_async=False)
766- # streaming_flux_sync = use("", streaming=True, use_async=False)
767- # flux_async = use("", use_async=True)
768- # streaming_flux_async = use("", streaming=True, use_async=True)
769-
770- # flux = use("", hint=model)
771- # flux_sync = use("", hint=model, use_async=False)
772- # streaming_flux_sync = use("", hint=model, streaming=False, use_async=False)
773- # flux_async = use("", hint=model, use_async=True)
774- # streaming_flux_async = use("", hint=model, streaming=True, use_async=True)
775-
776- # flux = use(Model())
777- # flux_sync = use(Model(), use_async=False)
778- # streaming_flux_sync = use(Model(), streaming=False, use_async=False)
779- # flux_async = use(Model(), use_async=True)
780- # streaming_flux_async = use(Model(), streaming=True, use_async=True)
0 commit comments