11import json
2- from collections .abc import Callable
2+ from collections .abc import Callable , Generator
33from typing import TypeVar , Generic
44
55
@@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
1919ENTITY = TypeVar ('ENTITY' )
2020
2121
22- class Pagination (Generic [ENTITY ]):
22+ class Pagination (Generic [ENTITY ], Generator [ ENTITY , None , None ] ):
2323 def __init__ (self , first_page : JsonObject ,
2424 total_result : int ,
2525 next_page_loader : Callable [[JsonObject ], JsonObject | None ],
@@ -37,10 +37,7 @@ def __init__(self, first_page: JsonObject,
3737 def total_results (self ) -> int :
3838 return self ._total_results
3939
40- def __iter__ (self ):
41- return self
42-
43- def __next__ (self ) -> ENTITY :
40+ def send (self , value ) -> ENTITY :
4441 try :
4542 if self ._cursor is None :
4643 self ._current_page = self ._first_page
@@ -52,3 +49,15 @@ def __next__(self) -> ENTITY:
5249 raise
5350 self ._cursor = self ._resources_accessor (self ._current_page ).__iter__ ()
5451 return self ._instance_creator (self ._cursor .__next__ ())
52+
53+ def throw (self , typ , val = None , tb = None ):
54+ super ().throw (typ , val , tb )
55+
56+ def close (self ):
57+ super ().close ()
58+
59+ def __iter__ (self ):
60+ return self
61+
62+ def __next__ (self ) -> ENTITY :
63+ return self .send (None )
0 commit comments