Skip to content

Commit 426d8a5

Browse files
committed
Resolve pyright isues in generator.py and listing.py
1 parent 5cd8031 commit 426d8a5

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

praw/models/listing/generator.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
from typing import TYPE_CHECKING, Any
88

99
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
1111

1212
if TYPE_CHECKING:
1313
import praw
14+
from praw.models.reddit.base import RedditBase
1415

1516

1617
class ListingGenerator(PRAWBase, Iterator):
@@ -47,30 +48,31 @@ def __init__(
4748
super().__init__(reddit, _data=None)
4849
self._exhausted = False
4950
self._listing = None
50-
self._list_index = None
51+
self._list_index: int
5152
self.limit = limit
5253
self.params = deepcopy(params) if params else {}
5354
self.params["limit"] = limit or 1024
5455
self.url = url
5556
self.yielded = 0
5657

57-
def __iter__(self) -> Any:
58+
def __iter__(self) -> ListingGenerator:
5859
"""Permit :class:`.ListingGenerator` to operate as an iterator."""
5960
return self
6061

61-
def __next__(self) -> Any:
62+
def __next__(self) -> RedditBase:
6263
"""Permit :class:`.ListingGenerator` to operate as a generator."""
6364
if self.limit is not None and self.yielded >= self.limit:
6465
raise StopIteration
6566

6667
if self._listing is None or self._list_index >= len(self._listing):
6768
self._next_batch()
69+
assert self._listing is not None
6870

6971
self._list_index += 1
7072
self.yielded += 1
7173
return self._listing[self._list_index - 1]
7274

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:
7476
if isinstance(listing, list):
7577
return listing[1] # for submission duplicates
7678
if isinstance(listing, dict):

praw/models/listing/listing.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22

33
from __future__ import annotations
44

5-
from typing import Any
5+
from typing import TYPE_CHECKING, Any
66

77
from praw.models.base import PRAWBase
88

9+
if TYPE_CHECKING:
10+
from praw.models.reddit.base import RedditBase
11+
912

1013
class Listing(PRAWBase):
1114
"""A listing is a collection of :class:`.RedditBase` instances."""
1215

16+
if TYPE_CHECKING:
17+
after: Any
18+
1319
AFTER_PARAM = "after"
1420
CHILD_ATTRIBUTE = "children"
1521

@@ -64,6 +70,9 @@ class ModmailConversationsListing(Listing):
6470

6571
CHILD_ATTRIBUTE = "conversations"
6672

73+
if TYPE_CHECKING:
74+
conversations: list[RedditBase]
75+
6776
@property
6877
def after(self) -> str | None:
6978
"""Return the next attribute or ``None``."""

praw/reddit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def request(self, *args, **kwargs):
180180
181181
"""
182182
self._core = self._authorized_core = self._read_only_core = None
183-
self._objector = None
183+
self._objector: Objector
184184
self._unique_counter = 0
185185

186186
try:

0 commit comments

Comments
 (0)