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/redditor.py #1206

Merged
merged 5 commits into from
Dec 29, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions praw/models/listing/mixins/redditor.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Provide the RedditorListingMixin class."""
from typing import Any, Dict, Generator, TypeVar, Union
from urllib.parse import urljoin

from ....util.cache import cachedproperty
from ..generator import ListingGenerator
from .base import BaseListingMixin
from .gilded import GildedListingMixin

Reddit = TypeVar("Reddit")
_SubListing = TypeVar("_SubListing")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordering or _.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it breaks the class sort order, I think it'd be preferable to define the SubListing class before RedditorListingMixin to avoid needing to use an underscore. Will you do that please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.



class RedditorListingMixin(BaseListingMixin, GildedListingMixin):
"""Adds additional methods pertaining to Redditor instances."""

@cachedproperty
def comments(self):
def comments(self) -> _SubListing:
r"""Provide an instance of :class:`.SubListing` for comment access.

For example, to output the first line of all new comments by
Expand All @@ -26,7 +30,7 @@ def comments(self):
return SubListing(self._reddit, self._path, "comments")

@cachedproperty
def submissions(self):
def submissions(self) -> _SubListing:
"""Provide an instance of :class:`.SubListing` for submission access.

For example, to output the title's of top 100 of all time submissions
Expand All @@ -40,7 +44,9 @@ def submissions(self):
"""
return SubListing(self._reddit, self._path, "submitted")

def downvoted(self, **generator_kwargs):
def downvoted(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for items the user has downvoted.

May raise ``prawcore.Forbidden`` after issuing the request if the user
Expand All @@ -56,7 +62,9 @@ def downvoted(self, **generator_kwargs):
self._reddit, urljoin(self._path, "downvoted"), **generator_kwargs
)

def gildings(self, **generator_kwargs):
def gildings(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for items the user has gilded.

May raise ``prawcore.Forbidden`` after issuing the request if the user
Expand All @@ -74,7 +82,9 @@ def gildings(self, **generator_kwargs):
**generator_kwargs
)

def hidden(self, **generator_kwargs):
def hidden(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for items the user has hidden.

May raise ``prawcore.Forbidden`` after issuing the request if the user
Expand All @@ -90,7 +100,9 @@ def hidden(self, **generator_kwargs):
self._reddit, urljoin(self._path, "hidden"), **generator_kwargs
)

def saved(self, **generator_kwargs):
def saved(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for items the user has saved.

May raise ``prawcore.Forbidden`` after issuing the request if the user
Expand All @@ -106,7 +118,9 @@ def saved(self, **generator_kwargs):
self._reddit, urljoin(self._path, "saved"), **generator_kwargs
)

def upvoted(self, **generator_kwargs):
def upvoted(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Any, None, None]:
"""Return a :class:`.ListingGenerator` for items the user has upvoted.

May raise ``prawcore.Forbidden`` after issuing the request if the user
Expand All @@ -126,7 +140,7 @@ def upvoted(self, **generator_kwargs):
class SubListing(BaseListingMixin):
"""Helper class for generating :class:`.ListingGenerator` objects."""

def __init__(self, reddit, base_path, subpath):
def __init__(self, reddit: Reddit, base_path: str, subpath: str):
"""Initialize a SubListing instance.

:param reddit: An instance of :class:`.Reddit`.
Expand Down