Skip to content

Commit

Permalink
Sort praw.models.util.stream_generator arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Jan 15, 2022
1 parent 1f06cd2 commit 8345276
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
6 changes: 3 additions & 3 deletions praw/models/reddit/subreddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,9 +2757,9 @@ def log(
"""
return stream_generator(
self.subreddit.mod.log,
attribute_name="id",
action=action,
mod=mod,
attribute_name="id",
**stream_options,
)

Expand Down Expand Up @@ -2799,11 +2799,11 @@ def modmail_conversations(
self.subreddit = self.subreddit._reddit.subreddit("all")
return stream_generator(
self.subreddit.modmail.conversations,
attribute_name="id",
exclude_before=True,
other_subreddits=other_subreddits,
sort=sort,
state=state,
attribute_name="id",
exclude_before=True,
**stream_options,
)

Expand Down
22 changes: 13 additions & 9 deletions praw/models/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random
import time
from collections import OrderedDict
from typing import Any, Callable, Generator, List, Optional, Set
from typing import Any, Callable, Generator, List, Optional, Set, Union

from ..util import _deprecate_args

Expand Down Expand Up @@ -89,30 +89,34 @@ def permissions_string(
return ",".join(to_set)


@_deprecate_args(
"function", "pause_after", "skip_existing", "attribute_name", "exclude_before"
)
def stream_generator(
function: Callable[[Any], Any],
pause_after: Optional[int] = None,
skip_existing: bool = False,
function: Callable,
*,
attribute_name: str = "fullname",
exclude_before: bool = False,
pause_after: Optional[int] = None,
skip_existing: bool = False,
**function_kwargs: Any,
) -> Generator[Any, None, None]:
"""Yield new items from ListingGenerators and ``None`` when paused.
"""Yield new items from ``function`` as they become available.
:param function: A callable that returns a :class:`.ListingGenerator`, e.g.,
:meth:`.Subreddit.comments` or :meth:`.Subreddit.new`.
:param attribute_name: The field to use as an ID (default: ``"fullname"``).
:param exclude_before: When ``True`` does not pass ``params`` to ``function``
(default: ``False``).
:param pause_after: An integer representing the number of requests that result in no
new items before this function yields ``None``, effectively introducing a pause
into the stream. A negative value yields ``None`` after items from a single
response have been yielded, regardless of number of new items obtained in that
response. A value of ``0`` yields ``None`` after every response resulting in no
new items, and a value of ``None`` never introduces a pause (default: ``None``).
:param skip_existing: When ``True`` does not yield any results from the first
:param skip_existing: When ``True``, this does not yield any results from the first
request thereby skipping any items that existed in the stream prior to starting
the stream (default: ``False``).
:param attribute_name: The field to use as an ID (default: ``"fullname"``).
:param exclude_before: When ``True`` does not pass ``params`` to ``functions``
(default: ``False``).
Additional keyword arguments will be passed to ``function``.
Expand Down

0 comments on commit 8345276

Please sign in to comment.