Skip to content

Commit

Permalink
(#1164) Add types to reddit/multi.py (#1220)
Browse files Browse the repository at this point in the history
(#1164) Add types to reddit/multi.py
  • Loading branch information
PythonCoderAS authored and bboe committed Dec 29, 2019
1 parent 067b81e commit 6871e49
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions praw/models/reddit/multi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provide the Multireddit class."""
from json import dumps
import re
from json import dumps
from typing import Any, Dict, List, Optional, TypeVar, Union

from ...const import API_PATH
from ...util.cache import cachedproperty
Expand All @@ -9,6 +10,9 @@
from .redditor import Redditor
from .subreddit import Subreddit, SubredditStream

_Multireddit = TypeVar("_Multireddit")
Reddit = TypeVar("Reddit")


class Multireddit(SubredditListingMixin, RedditBase):
r"""A class for users' Multireddits.
Expand Down Expand Up @@ -50,7 +54,7 @@ class Multireddit(SubredditListingMixin, RedditBase):
RE_INVALID = re.compile(r"[\W_]+", re.UNICODE)

@staticmethod
def sluggify(title):
def sluggify(title: str):
"""Return a slug version of the title.
:param title: The title to make a slug of.
Expand All @@ -67,7 +71,7 @@ def sluggify(title):
return title or "_"

@cachedproperty
def stream(self):
def stream(self) -> SubredditStream:
"""Provide an instance of :class:`.SubredditStream`.
Streams can be used to indefinitely retrieve new comments made to a
Expand All @@ -90,7 +94,7 @@ def stream(self):
"""
return SubredditStream(self)

def __init__(self, reddit, _data):
def __init__(self, reddit: Reddit, _data: Dict[str, Any]):
"""Construct an instance of the Multireddit object."""
self.path = None
super().__init__(reddit, _data=_data)
Expand Down Expand Up @@ -123,7 +127,7 @@ def _fetch(self):
self.__dict__.update(other.__dict__)
self._fetched = True

def add(self, subreddit):
def add(self, subreddit: Subreddit):
"""Add a subreddit to this multireddit.
:param subreddit: The subreddit to add to this multi.
Expand All @@ -137,7 +141,7 @@ def add(self, subreddit):
)
self._reset_attributes("subreddits")

def copy(self, display_name=None):
def copy(self, display_name: Optional[str] = None) -> _Multireddit:
"""Copy this multireddit and return the new multireddit.
:param display_name: (optional) The display name for the copied
Expand Down Expand Up @@ -167,7 +171,7 @@ def delete(self):
)
self._reddit.request("DELETE", path)

def remove(self, subreddit):
def remove(self, subreddit: Subreddit):
"""Remove a subreddit from this multireddit.
:param subreddit: The subreddit to remove from this multi.
Expand All @@ -181,7 +185,9 @@ def remove(self, subreddit):
)
self._reset_attributes("subreddits")

def update(self, **updated_settings):
def update(
self, **updated_settings: Union[str, List[Union[str, Subreddit]]]
):
"""Update this multireddit.
Keyword arguments are passed for settings that should be updated. They
Expand Down

0 comments on commit 6871e49

Please sign in to comment.