Skip to content

Commit 5cd8031

Browse files
committed
Replace uses of Generator[T, None, None] with Iterator[T]
1 parent b2d4968 commit 5cd8031

9 files changed

Lines changed: 40 additions & 42 deletions

File tree

praw/models/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from praw.models.reddit.multi import Multireddit, Subreddit
1313

1414
if TYPE_CHECKING:
15-
from collections.abc import Generator
15+
from collections.abc import Iterator
1616

1717
import praw.models
1818

@@ -180,7 +180,7 @@ def create(
180180
},
181181
)
182182

183-
def info(self, ids: list[str]) -> Generator[praw.models.LiveThread, None, None]:
183+
def info(self, ids: list[str]) -> Iterator[praw.models.LiveThread]:
184184
"""Fetch information about each live thread in ``ids``.
185185
186186
:param ids: A list of IDs for a live thread.
@@ -213,7 +213,7 @@ def info(self, ids: list[str]) -> Generator[praw.models.LiveThread, None, None]:
213213
msg = "ids must be a list"
214214
raise TypeError(msg)
215215

216-
def generator() -> Generator[praw.models.LiveThread, None, None]:
216+
def generator() -> Iterator[praw.models.LiveThread]:
217217
for position in range(0, len(ids), 100):
218218
ids_chunk = ids[position : position + 100]
219219
url = API_PATH["live_info"].format(ids=",".join(ids_chunk))

praw/models/mod_notes.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from praw.models.reddit.submission import Submission
1313

1414
if TYPE_CHECKING:
15-
from collections.abc import Generator
15+
from collections.abc import Iterator
1616

1717
import praw.models
1818
from praw.models.reddit.redditor import Redditor
@@ -49,7 +49,7 @@ def _all_generator(
4949

5050
def _bulk_generator(
5151
self, redditors: list[Redditor | str], subreddits: list[Subreddit | str]
52-
) -> Generator[praw.models.ModNote, None, None]:
52+
) -> Iterator[praw.models.ModNote]:
5353
subreddits_iter = iter(subreddits)
5454
redditors_iter = iter(redditors)
5555
while True:
@@ -79,7 +79,7 @@ def _notes(
7979
redditors: list[Redditor | str],
8080
subreddits: list[Subreddit | str],
8181
**generator_kwargs: Any,
82-
) -> Generator[praw.models.ModNote, None, None]:
82+
) -> Iterator[praw.models.ModNote]:
8383
if all_notes:
8484
for subreddit in subreddits:
8585
for redditor in redditors:
@@ -304,7 +304,7 @@ def subreddits(
304304
*subreddits: Subreddit | str,
305305
all_notes: bool | None = None,
306306
**generator_kwargs: Any,
307-
) -> Generator[praw.models.ModNote, None, None]:
307+
) -> Iterator[praw.models.ModNote]:
308308
"""Return notes for this :class:`.Redditor` from one or more subreddits.
309309
310310
:param subreddits: One or more subreddits to retrieve the notes from. Must be
@@ -400,7 +400,7 @@ def redditors(
400400
*redditors: Redditor | str,
401401
all_notes: bool | None = None,
402402
**generator_kwargs: Any,
403-
) -> Generator[praw.models.ModNote, None, None]:
403+
) -> Iterator[praw.models.ModNote]:
404404
"""Return notes from this :class:`.Subreddit` for one or more redditors.
405405
406406
:param redditors: One or more redditors to retrieve notes for. Must be either a
@@ -494,7 +494,7 @@ def __call__(
494494
subreddits: list[Subreddit | str] | None = None,
495495
things: list[Comment | Submission] | None = None,
496496
**generator_kwargs: Any,
497-
) -> Generator[praw.models.ModNote, None, None]:
497+
) -> Iterator[praw.models.ModNote]:
498498
"""Get note(s) for each subreddit/user pair, or ``None`` if they don't have any.
499499
500500
:param all_notes: Whether to return all notes or only the latest note for each
@@ -636,7 +636,7 @@ def things(
636636
*things: Comment | Submission,
637637
all_notes: bool | None = None,
638638
**generator_kwargs: Any,
639-
) -> Generator[praw.models.ModNote, None, None]:
639+
) -> Iterator[praw.models.ModNote]:
640640
"""Return notes associated with the author of a :class:`.Comment` or :class:`.Submission`.
641641
642642
:param things: One or more things to return notes on. Must be a

praw/models/reddit/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from praw.util.cache import cachedproperty
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Generator, Iterator
16+
from collections.abc import Iterator
1717

1818
import praw.models
1919

@@ -359,7 +359,7 @@ def __init__(
359359
super().__init__(reddit, _data)
360360
self.subreddit = subreddit
361361

362-
def __iter__(self) -> Generator[Collection, None, None]:
362+
def __iter__(self) -> Iterator[Collection]:
363363
r"""Iterate over the :class:`.Subreddit`'s :class:`.Collection`\ s.
364364
365365
Example usage:

praw/models/reddit/mixins/modnote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from typing import TYPE_CHECKING, Any
66

77
if TYPE_CHECKING:
8-
from collections.abc import Generator
8+
from collections.abc import Iterator
99

1010
import praw.models
1111

1212

1313
class ModNoteMixin:
1414
"""Interface for classes that can have a moderator note set on them."""
1515

16-
def author_notes(self, **generator_kwargs: Any) -> Generator[praw.models.ModNote, None, None]:
16+
def author_notes(self, **generator_kwargs: Any) -> Iterator[praw.models.ModNote]:
1717
"""Get the moderator notes for the author of this object in the subreddit it's posted in.
1818
1919
:param generator_kwargs: Additional keyword arguments are passed in the

praw/models/reddit/redditor.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from praw.util.cache import cachedproperty
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Generator
16+
from collections.abc import Iterator
1717

1818
import praw.models
1919

@@ -420,7 +420,7 @@ def __init__(self, redditor: praw.models.Redditor) -> None:
420420
"""
421421
self.redditor = redditor
422422

423-
def comments(self, **stream_options: str | int | dict[str, str]) -> Generator[praw.models.Comment, None, None]:
423+
def comments(self, **stream_options: str | int | dict[str, str]) -> Iterator[praw.models.Comment]:
424424
"""Yield new comments as they become available.
425425
426426
Comments are yielded oldest first. Up to 100 historical comments will initially
@@ -438,9 +438,7 @@ def comments(self, **stream_options: str | int | dict[str, str]) -> Generator[pr
438438
"""
439439
return stream_generator(self.redditor.comments.new, **stream_options)
440440

441-
def submissions(
442-
self, **stream_options: str | int | dict[str, str]
443-
) -> Generator[praw.models.Submission, None, None]:
441+
def submissions(self, **stream_options: str | int | dict[str, str]) -> Iterator[praw.models.Submission]:
444442
"""Yield new submissions as they become available.
445443
446444
Submissions are yielded oldest first. Up to 100 historical submissions will

praw/models/reddit/submission.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from praw.util import cachedproperty
2424

2525
if TYPE_CHECKING:
26-
from collections.abc import Generator
26+
from collections.abc import Iterator
2727

2828
import praw.models
2929

@@ -621,7 +621,7 @@ def _chunk(
621621
*,
622622
chunk_size: int,
623623
other_submissions: list[praw.models.Submission] | None,
624-
) -> Generator[str, None, None]:
624+
) -> Iterator[str]:
625625
all_submissions = [self.fullname]
626626
if other_submissions:
627627
all_submissions += [x.fullname for x in other_submissions]

praw/models/reddit/subreddit.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def create(
224224
}
225225
return self.subreddit._reddit.post(API_PATH["modmail_conversations"], data=data)
226226

227-
def subreddits(self) -> Generator[praw.models.Subreddit, None, None]:
227+
def subreddits(self) -> Iterator[praw.models.Subreddit]:
228228
"""Yield subreddits using the new modmail that the user moderates.
229229
230230
For example:
@@ -284,7 +284,7 @@ def __init__(self, subreddit: praw.models.Subreddit) -> None:
284284
"""
285285
self.subreddit = subreddit
286286

287-
def __iter__(self) -> Generator[praw.models.Subreddit, None, None]:
287+
def __iter__(self) -> Iterator[praw.models.Subreddit]:
288288
"""Iterate through the special :class:`.Subreddit`'s filters.
289289
290290
This method should be invoked as:
@@ -597,7 +597,7 @@ def __init__(self, subreddit: praw.models.Subreddit) -> None:
597597
"""
598598
self.subreddit = subreddit
599599

600-
def __iter__(self) -> Generator[None, None, None]:
600+
def __iter__(self) -> Iterator[None]:
601601
"""Abstract method to return flair templates."""
602602
raise NotImplementedError
603603

@@ -1112,7 +1112,7 @@ def __init__(self, subreddit: praw.models.Subreddit) -> None:
11121112

11131113
def edited(
11141114
self, *, only: str | None = None, **stream_options: Any
1115-
) -> Generator[praw.models.Comment | praw.models.Submission, None, None]:
1115+
) -> Iterator[praw.models.Comment | praw.models.Submission]:
11161116
"""Yield edited comments and submissions as they become available.
11171117
11181118
:param only: If specified, one of ``"comments"`` or ``"submissions"`` to yield
@@ -1137,7 +1137,7 @@ def log(
11371137
action: str | None = None,
11381138
mod: str | praw.models.Redditor | None = None,
11391139
**stream_options: Any,
1140-
) -> Generator[praw.models.ModAction, None, None]:
1140+
) -> Iterator[praw.models.ModAction]:
11411141
"""Yield moderator log entries as they become available.
11421142
11431143
:param action: If given, only return log entries for the specified action.
@@ -1168,7 +1168,7 @@ def modmail_conversations(
11681168
sort: str | None = None,
11691169
state: str | None = None,
11701170
**stream_options: Any,
1171-
) -> Generator[ModmailConversation, None, None]:
1171+
) -> Iterator[ModmailConversation]:
11721172
"""Yield new-modmail conversations as they become available.
11731173
11741174
:param other_subreddits: A list of :class:`.Subreddit` instances for which to
@@ -1206,7 +1206,7 @@ def modmail_conversations(
12061206

12071207
def modqueue(
12081208
self, *, only: str | None = None, **stream_options: Any
1209-
) -> Generator[praw.models.Comment | praw.models.Submission, None, None]:
1209+
) -> Iterator[praw.models.Comment | praw.models.Submission]:
12101210
r"""Yield :class:`.Comment`\ s and :class:`.Submission`\ s in the modqueue as they become available.
12111211
12121212
:param only: If specified, one of ``"comments"`` or ``"submissions"`` to yield
@@ -1226,7 +1226,7 @@ def modqueue(
12261226

12271227
def reports(
12281228
self, *, only: str | None = None, **stream_options: Any
1229-
) -> Generator[praw.models.Comment | praw.models.Submission, None, None]:
1229+
) -> Iterator[praw.models.Comment | praw.models.Submission]:
12301230
r"""Yield reported :class:`.Comment`\ s and :class:`.Submission`\ s as they become available.
12311231
12321232
:param only: If specified, one of ``"comments"`` or ``"submissions"`` to yield
@@ -1246,7 +1246,7 @@ def reports(
12461246

12471247
def spam(
12481248
self, *, only: str | None = None, **stream_options: Any
1249-
) -> Generator[praw.models.Comment | praw.models.Submission, None, None]:
1249+
) -> Iterator[praw.models.Comment | praw.models.Submission]:
12501250
r"""Yield spam :class:`.Comment`\ s and :class:`.Submission`\ s as they become available.
12511251
12521252
:param only: If specified, one of ``"comments"`` or ``"submissions"`` to yield
@@ -1264,7 +1264,7 @@ def spam(
12641264
"""
12651265
return stream_generator(self.subreddit.mod.spam, only=only, **stream_options)
12661266

1267-
def unmoderated(self, **stream_options: Any) -> Generator[praw.models.Submission, None, None]:
1267+
def unmoderated(self, **stream_options: Any) -> Iterator[praw.models.Submission]:
12681268
r"""Yield unmoderated :class:`.Submission`\ s as they become available.
12691269
12701270
Keyword arguments are passed to :func:`.stream_generator`.
@@ -1413,7 +1413,7 @@ def __init__(self, subreddit: praw.models.Subreddit) -> None:
14131413
"""
14141414
self.subreddit = subreddit
14151415

1416-
def comments(self, **stream_options: Any) -> Generator[praw.models.Comment, None, None]:
1416+
def comments(self, **stream_options: Any) -> Iterator[praw.models.Comment]:
14171417
"""Yield new comments as they become available.
14181418
14191419
Comments are yielded oldest first. Up to 100 historical comments will initially
@@ -1445,7 +1445,7 @@ def comments(self, **stream_options: Any) -> Generator[praw.models.Comment, None
14451445
"""
14461446
return stream_generator(self.subreddit.comments, **stream_options)
14471447

1448-
def submissions(self, **stream_options: Any) -> Generator[praw.models.Submission, None, None]:
1448+
def submissions(self, **stream_options: Any) -> Iterator[praw.models.Submission]:
14491449
r"""Yield new :class:`.Submission`\ s as they become available.
14501450
14511451
Submissions are yielded oldest first. Up to 100 historical submissions will
@@ -1925,7 +1925,7 @@ def __init__(self, subreddit: praw.models.Subreddit) -> None:
19251925
self.contributor = SubredditRelationship(subreddit, "wikicontributor")
19261926
self.subreddit = subreddit
19271927

1928-
def __iter__(self) -> Generator[WikiPage, None, None]:
1928+
def __iter__(self) -> Iterator[WikiPage]:
19291929
"""Iterate through the pages of the wiki.
19301930
19311931
This method is to be used to discover all wikipages for a subreddit:
@@ -3661,7 +3661,7 @@ class SubredditLinkFlairTemplates(SubredditFlairTemplates):
36613661

36623662
def __iter__(
36633663
self,
3664-
) -> Generator[dict[str, str | int | bool | list[dict[str, str]]], None, None]:
3664+
) -> Iterator[dict[str, str | int | bool | list[dict[str, str]]]]:
36653665
"""Iterate through the link flair templates as a moderator.
36663666
36673667
For example:
@@ -3758,7 +3758,7 @@ def reorder(self, flair_list: list[str]) -> None:
37583758

37593759
def user_selectable(
37603760
self,
3761-
) -> Generator[dict[str, str | bool], None, None]:
3761+
) -> Iterator[dict[str, str | bool]]:
37623762
"""Iterate through the link flair templates as a regular user.
37633763
37643764
For example:
@@ -3778,7 +3778,7 @@ class SubredditRedditorFlairTemplates(SubredditFlairTemplates):
37783778

37793779
def __iter__(
37803780
self,
3781-
) -> Generator[dict[str, str | int | bool | list[dict[str, str]]], None, None]:
3781+
) -> Iterator[dict[str, str | int | bool | list[dict[str, str]]]]:
37823782
"""Iterate through the user flair templates.
37833783
37843784
For example:

praw/models/reddit/wikipage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from praw.util.cache import cachedproperty
1212

1313
if TYPE_CHECKING:
14-
from collections.abc import Generator, Iterator
14+
from collections.abc import Iterator
1515

1616
import praw.models
1717

@@ -174,7 +174,7 @@ def _revision_generator(
174174
generator_kwargs: dict[str, Any],
175175
subreddit: praw.models.Subreddit,
176176
url: str,
177-
) -> Generator[dict[str, Redditor | WikiPage | str | int | bool | None], None, None]:
177+
) -> Iterator[dict[str, Redditor | WikiPage | str | int | bool | None]]:
178178
for revision in ListingGenerator(subreddit._reddit, url, **generator_kwargs):
179179
if revision["author"] is not None:
180180
revision["author"] = Redditor(subreddit._reddit, _data=revision["author"]["data"])
@@ -289,7 +289,7 @@ def revision(self, revision: str) -> WikiPage:
289289
"""
290290
return WikiPage(self.subreddit._reddit, self.subreddit, self.name, revision)
291291

292-
def revisions(self, **generator_kwargs: str | int | dict[str, str]) -> Generator[WikiPage, None, None]:
292+
def revisions(self, **generator_kwargs: str | int | dict[str, str]) -> Iterator[WikiPage]:
293293
"""Return a :class:`.ListingGenerator` for page revisions.
294294
295295
Additional keyword arguments are passed in the initialization of

praw/models/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import TYPE_CHECKING, Any, Callable
99

1010
if TYPE_CHECKING:
11-
from collections.abc import Generator
11+
from collections.abc import Iterator
1212

1313

1414
def permissions_string(*, known_permissions: set[str], permissions: list[str] | None) -> str:
@@ -42,7 +42,7 @@ def stream_generator(
4242
pause_after: int | None = None,
4343
skip_existing: bool = False,
4444
**function_kwargs: Any,
45-
) -> Generator[Any, None, None]:
45+
) -> Iterator[Any]:
4646
"""Yield new items from ``function`` as they become available.
4747
4848
:param function: A callable that returns a :class:`.ListingGenerator`, e.g.,

0 commit comments

Comments
 (0)