Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1164) Add types to listing/mixins/subreddit.py #1209

Merged
merged 4 commits into from
Dec 30, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions praw/models/listing/mixins/subreddit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provide the SubredditListingMixin class."""
from typing import Any, Dict, Generator, TypeVar, Union
from urllib.parse import urljoin

from ....util.cache import cachedproperty
Expand All @@ -8,14 +9,19 @@
from .gilded import GildedListingMixin
from .rising import RisingListingMixin

Comment = TypeVar("Comment")
_CommentHelper = TypeVar("_CommentHelper")
PythonCoderAS marked this conversation as resolved.
Show resolved Hide resolved
Reddit = TypeVar("Reddit")
Subreddit = TypeVar("Subreddit")


class SubredditListingMixin(
BaseListingMixin, GildedListingMixin, RisingListingMixin
):
"""Adds additional methods pertaining to Subreddit-like instances."""

@cachedproperty
def comments(self):
def comments(self) -> _CommentHelper:
"""Provide an instance of :class:`.CommentHelper`.

For example, to output the author of the 25 most recent comments of
Expand All @@ -29,7 +35,7 @@ def comments(self):
"""
return CommentHelper(self)

def __init__(self, reddit, _data):
def __init__(self, reddit: Reddit, _data: Dict[str, Any]):
"""Initialize a SubredditListingMixin instance.

:param reddit: An instance of :class:`.Reddit`.
Expand All @@ -45,12 +51,14 @@ class CommentHelper(PRAWBase):
def _path(self):
return urljoin(self.subreddit._path, "comments/")

def __init__(self, subreddit):
def __init__(self, subreddit: Subreddit):
"""Initialize a CommentHelper instance."""
super().__init__(subreddit._reddit, _data=None)
self.subreddit = subreddit

def __call__(self, **generator_kwargs):
def __call__(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for the Subreddit's comments.

Additional keyword arguments are passed in the initialization of
Expand Down