4545 deduplicate_unhashable ,
4646 deep_get ,
4747 extends ,
48+ find_user_stacklevel ,
4849 representation ,
4950 validate_positive_int ,
50- warn_stacklevel ,
5151)
5252
53- _PageType : TypeAlias = ItemPage [Any ] | RawAPIPageResponse
54- _PageList : TypeAlias = list [_PageType ]
55- _PageT = TypeVar ("_PageT" , bound = _PageType )
53+ ProcessedPages : TypeAlias = list [RawAPIItem ] | ItemPage [_T ]
54+ _PageType : TypeAlias = RawAPIPageResponse | ItemPage [_T ]
55+ _PageList : TypeAlias = list [_PageType [_T ]]
56+ _PageT = TypeVar ("_PageT" , bound = _PageType [Any ])
5657
5758
5859if TYPE_CHECKING :
59- _PageClass : TypeAlias = type [ItemPage [Any ] | RawAPIPageResponse ]
60- _PageFactory : TypeAlias = Callable [[_PageList ], _PageClass ]
61- _PageFactoryMap : TypeAlias = Mapping ["CollectReturnFormat" , _PageFactory ]
60+ _PageFactoryMap : TypeAlias = Mapping [
61+ "CollectReturnFormat" ,
62+ Callable [[_PageList [Any ]], type [RawAPIPageResponse | ItemPage [Any ]]],
63+ ]
6264 _OptionalTimestampPaginationConfig : TypeAlias = (
6365 "TimestampPaginationConfig | Literal[False]"
6466 )
@@ -336,7 +338,7 @@ def warn_if_exceeds_safe(max_pages: int, /) -> int:
336338 f"The computed number of pages ({ max_pages } ) exceeds the "
337339 f"recommended safe maximum ({ self .__class__ .SAFE_MAX_PAGES } ). "
338340 "Proceed at your own risk." ,
339- stacklevel = warn_stacklevel (),
341+ stacklevel = find_user_stacklevel (),
340342 )
341343 return max_pages
342344
@@ -396,7 +398,7 @@ def _remove_pagination_args(**kwargs: _T) -> dict[str, _T]:
396398 f"Pagination parameters { _PAGINATION_ARGS } should not be "
397399 "provided by users. These parameters are managed internally "
398400 "by the pagination system." ,
399- stacklevel = warn_stacklevel (),
401+ stacklevel = find_user_stacklevel (),
400402 )
401403 return kwargs
402404
@@ -424,7 +426,7 @@ def _validate_unix_config(
424426
425427 @staticmethod
426428 def _extract_unix_timestamp (
427- cfg : TimestampPaginationConfig , page : _PageType | None , /
429+ cfg : TimestampPaginationConfig , page : _PageType [ Any ] | None , /
428430 ) -> int | None :
429431 if not page :
430432 return None
@@ -460,16 +462,16 @@ def _validate_unix_pagination_parameter(
460462 warnings .warn (
461463 "The parameters 'start' and 'to' will be managed automatically with Unix "
462464 "timestamp pagination. Your provided values will be ignored." ,
463- stacklevel = warn_stacklevel (),
465+ stacklevel = find_user_stacklevel (),
464466 )
465467
466468 @classmethod
467469 def _process_collected_pages (
468470 cls ,
469- collection : list [ RawAPIPageResponse | ItemPage [ _T ] ],
471+ collection : _PageList [ _T ],
470472 return_format : CollectReturnFormat ,
471473 deduplicate : bool , # noqa: FBT001
472- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
474+ ) -> ProcessedPages [_T ]:
473475 if cls ._COLLECT_RETURN_FORMATS [return_format ](collection ) is dict :
474476 raw = chain .from_iterable (
475477 p [RAW_RESPONSE_ITEMS_KEY ] for p in collection if isinstance (p , dict )
@@ -481,7 +483,7 @@ def _process_collected_pages(
481483 @classmethod
482484 def _deduplicate_collection (
483485 cls , collection : Iterable [RawAPIItem ] | ItemPage [_T ], /
484- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
486+ ) -> ProcessedPages [_T ]:
485487 if not isinstance (collection , ItemPage ):
486488 return deduplicate_unhashable (collection )
487489 return collection .with_items (deduplicate_unhashable (collection )) # pyright: ignore[reportArgumentType, reportReturnType]
@@ -577,7 +579,7 @@ def collect(
577579 self : SyncPageIterator [RawAPIPageResponse ] | SyncPageIterator [ItemPage [_T ]],
578580 * ,
579581 deduplicate : bool = True ,
580- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
582+ ) -> ProcessedPages [_T ]:
581583 return self .__class__ .gather_from_iterator (self , deduplicate = deduplicate )
582584
583585 @classmethod
@@ -649,7 +651,7 @@ def gather_from_iterator(
649651 return_format : CollectReturnFormat = CollectReturnFormat .FIRST ,
650652 * ,
651653 deduplicate : bool = True ,
652- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
654+ ) -> ProcessedPages [_T ]:
653655 return cls ._process_collected_pages (list (iterator ), return_format , deduplicate )
654656
655657
@@ -669,7 +671,7 @@ async def collect(
669671
670672 async def collect (
671673 self : AsyncPageIterator [RawAPIPageResponse ] | AsyncPageIterator [ItemPage [_T ]],
672- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
674+ ) -> ProcessedPages [_T ]:
673675 return await self .__class__ .gather_from_iterator (self )
674676
675677 @classmethod
@@ -741,7 +743,7 @@ async def gather_from_iterator(
741743 return_format : CollectReturnFormat = CollectReturnFormat .FIRST ,
742744 * ,
743745 deduplicate : bool = True ,
744- ) -> list [ RawAPIItem ] | ItemPage [_T ]:
746+ ) -> ProcessedPages [_T ]:
745747 return cls ._process_collected_pages (
746748 [page async for page in iterator ], return_format , deduplicate
747749 )
0 commit comments