@@ -300,17 +300,15 @@ def cast(self, into: Type[U]) -> "stream[U]":
300300
301301 def buffer (
302302 self ,
303- up_to : int ,
303+ up_to : Optional [ int ] = None ,
304304 ) -> "stream[T]" :
305305 """
306- Buffer upstream elements into a bounded queue (max size ``up_to``), via a background task.
307-
308- Allow to decouple the upstream production rate from the downstream consumption rate.
306+ Buffer upstream elements into a queue, via a background task, decoupling upstream production rate from downstream consumption rate.
309307
310308 The background task is a thread during a sync iteration, and an async task during an async iteration.
311309
312310 Args:
313- up_to (``int``): The buffer size. Must be >= 1. When reached, upstream pulling pauses until an element is yielded out of the buffer.
311+ up_to (``int | None ``): The buffer size, must be >= 1 when set . When reached, upstream pulling pauses until an element is yielded out of the buffer.
314312
315313 Returns:
316314 ``stream[T]``: Upstream with buffering.
@@ -327,7 +325,8 @@ def buffer(
327325 time.sleep(1e-3)
328326 assert pulled == [0, 1, 2, 3, 4, 5]
329327 """
330- validate_int (up_to , gte = 1 , name = "up_to" )
328+ if up_to is not None :
329+ validate_int (up_to , gte = 1 , name = "up_to" )
331330 return BufferStream (self , up_to )
332331
333332 @overload
@@ -1082,7 +1081,7 @@ class BufferStream(DownStream[T, T]):
10821081 def __init__ (
10831082 self ,
10841083 upstream : stream [T ],
1085- up_to : int ,
1084+ up_to : Optional [ int ] ,
10861085 ) -> None :
10871086 super ().__init__ (upstream )
10881087 self ._up_to = up_to
0 commit comments