|
7 | 7 | from typing import TYPE_CHECKING, Any |
8 | 8 |
|
9 | 9 | from praw.models.base import PRAWBase |
10 | | -from praw.models.listing.listing import FlairListing, ModNoteListing |
| 10 | +from praw.models.listing.listing import FlairListing, Listing, ModNoteListing |
11 | 11 |
|
12 | 12 | if TYPE_CHECKING: |
13 | 13 | import praw |
| 14 | + from praw.models.reddit.base import RedditBase |
14 | 15 |
|
15 | 16 |
|
16 | 17 | class ListingGenerator(PRAWBase, Iterator): |
@@ -47,30 +48,31 @@ def __init__( |
47 | 48 | super().__init__(reddit, _data=None) |
48 | 49 | self._exhausted = False |
49 | 50 | self._listing = None |
50 | | - self._list_index = None |
| 51 | + self._list_index: int |
51 | 52 | self.limit = limit |
52 | 53 | self.params = deepcopy(params) if params else {} |
53 | 54 | self.params["limit"] = limit or 1024 |
54 | 55 | self.url = url |
55 | 56 | self.yielded = 0 |
56 | 57 |
|
57 | | - def __iter__(self) -> Any: |
| 58 | + def __iter__(self) -> ListingGenerator: |
58 | 59 | """Permit :class:`.ListingGenerator` to operate as an iterator.""" |
59 | 60 | return self |
60 | 61 |
|
61 | | - def __next__(self) -> Any: |
| 62 | + def __next__(self) -> RedditBase: |
62 | 63 | """Permit :class:`.ListingGenerator` to operate as a generator.""" |
63 | 64 | if self.limit is not None and self.yielded >= self.limit: |
64 | 65 | raise StopIteration |
65 | 66 |
|
66 | 67 | if self._listing is None or self._list_index >= len(self._listing): |
67 | 68 | self._next_batch() |
| 69 | + assert self._listing is not None |
68 | 70 |
|
69 | 71 | self._list_index += 1 |
70 | 72 | self.yielded += 1 |
71 | 73 | return self._listing[self._list_index - 1] |
72 | 74 |
|
73 | | - def _extract_sublist(self, listing: dict[str, Any] | list[Any] | Any) -> Any: |
| 75 | + def _extract_sublist(self, listing: dict[str, Any] | list[Listing]) -> Listing: |
74 | 76 | if isinstance(listing, list): |
75 | 77 | return listing[1] # for submission duplicates |
76 | 78 | if isinstance(listing, dict): |
|
0 commit comments