Skip to content

Commit

Permalink
(#1164) Add types to inbox.py (#1190)
Browse files Browse the repository at this point in the history
(#1164) Add types to inbox.py
  • Loading branch information
PythonCoderAS authored and bboe committed Dec 29, 2019
1 parent 57990c6 commit 9bb2914
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions praw/models/inbox.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
"""Provide the Front class."""
from typing import Dict, Generator, List, TypeVar, Union

from ..const import API_PATH
from .listing.generator import ListingGenerator
from .base import PRAWBase
from .util import stream_generator

Comment = TypeVar("Comment")
Message = TypeVar("Message")


class Inbox(PRAWBase):
"""Inbox is a Listing class that represents the Inbox."""

def all(self, **generator_kwargs):
def all(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Union[Message, Comment], None, None]:
"""Return a :class:`.ListingGenerator` for all inbox comments and messages.
Additional keyword arguments are passed in the initialization of
Expand All @@ -26,7 +33,7 @@ def all(self, **generator_kwargs):
self._reddit, API_PATH["inbox"], **generator_kwargs
)

def collapse(self, items):
def collapse(self, items: List[Message]):
"""Mark an inbox message as collapsed.
:param items: A list containing instances of :class:`.Message`.
Expand Down Expand Up @@ -54,7 +61,9 @@ def collapse(self, items):
self._reddit.post(API_PATH["collapse"], data=data)
items = items[25:]

def comment_replies(self, **generator_kwargs):
def comment_replies(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Comment, None, None]:
"""Return a :class:`.ListingGenerator` for comment replies.
Additional keyword arguments are passed in the initialization of
Expand All @@ -72,7 +81,7 @@ def comment_replies(self, **generator_kwargs):
self._reddit, API_PATH["comment_replies"], **generator_kwargs
)

def mark_read(self, items):
def mark_read(self, items: List[Union[Comment, Message]]):
"""Mark Comments or Messages as read.
:param items: A list containing instances of :class:`.Comment` and/or
Expand Down Expand Up @@ -102,7 +111,7 @@ def mark_read(self, items):
self._reddit.post(API_PATH["read_message"], data=data)
items = items[25:]

def mark_unread(self, items):
def mark_unread(self, items: List[Union[Comment, Message]]):
"""Unmark Comments or Messages as read.
:param items: A list containing instances of :class:`.Comment` and/or
Expand All @@ -128,7 +137,9 @@ def mark_unread(self, items):
self._reddit.post(API_PATH["unread_message"], data=data)
items = items[25:]

def mentions(self, **generator_kwargs):
def mentions(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Comment, None, None]:
r"""Return a :class:`.ListingGenerator` for mentions.
A mention is :class:`.Comment` in which the authorized redditor is
Expand All @@ -150,7 +161,7 @@ def mentions(self, **generator_kwargs):
self._reddit, API_PATH["mentions"], **generator_kwargs
)

def message(self, message_id):
def message(self, message_id: str) -> Message:
"""Return a Message corresponding to ``message_id``.
:param message_id: The base36 id of a message.
Expand All @@ -169,7 +180,9 @@ def message(self, message_id):
if message.id == message_id:
return message

def messages(self, **generator_kwargs):
def messages(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Message, None, None]:
"""Return a :class:`.ListingGenerator` for inbox messages.
Additional keyword arguments are passed in the initialization of
Expand All @@ -187,7 +200,9 @@ def messages(self, **generator_kwargs):
self._reddit, API_PATH["messages"], **generator_kwargs
)

def sent(self, **generator_kwargs):
def sent(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Message, None, None]:
"""Return a :class:`.ListingGenerator` for sent messages.
Additional keyword arguments are passed in the initialization of
Expand All @@ -206,7 +221,9 @@ def sent(self, **generator_kwargs):
self._reddit, API_PATH["sent"], **generator_kwargs
)

def stream(self, **stream_options):
def stream(
self, **stream_options: Union[str, int, Dict[str, str]]
) -> Generator[Union[Comment, Message], None, None]:
"""Yield new inbox items as they become available.
Items are yielded oldest first. Up to 100 historical items will
Expand All @@ -224,7 +241,9 @@ def stream(self, **stream_options):
"""
return stream_generator(self.unread, **stream_options)

def submission_replies(self, **generator_kwargs):
def submission_replies(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Comment, None, None]:
"""Return a :class:`.ListingGenerator` for submission replies.
Additional keyword arguments are passed in the initialization of
Expand All @@ -242,7 +261,7 @@ def submission_replies(self, **generator_kwargs):
self._reddit, API_PATH["submission_replies"], **generator_kwargs
)

def uncollapse(self, items):
def uncollapse(self, items: List[Message]):
"""Mark an inbox message as uncollapsed.
:param items: A list containing instances of :class:`.Message`.
Expand Down Expand Up @@ -270,7 +289,11 @@ def uncollapse(self, items):
self._reddit.post(API_PATH["uncollapse"], data=data)
items = items[25:]

def unread(self, mark_read=False, **generator_kwargs):
def unread(
self,
mark_read: bool = False,
**generator_kwargs: Union[str, int, Dict[str, str]]
) -> Generator[Union[Comment, Message], None, None]:
"""Return a :class:`.ListingGenerator` for unread comments and messages.
:param mark_read: Marks the inbox as read (default: False).
Expand Down

0 comments on commit 9bb2914

Please sign in to comment.