Skip to content

Commit

Permalink
(#1164) Add types to reddit/more.py (#1219)
Browse files Browse the repository at this point in the history
(#1164) Add types to reddit/more.py
  • Loading branch information
PythonCoderAS authored and bboe committed Dec 29, 2019
1 parent 9bb2914 commit 932fab7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions praw/models/reddit/more.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
"""Provide the MoreComments class."""
from typing import Any, Dict, List, TypeVar
from ...const import API_PATH
from ..base import PRAWBase

_MoreComments = TypeVar("_MoreComments")
Comment = TypeVar("Comment")
Reddit = TypeVar("Reddit")


class MoreComments(PRAWBase):
"""A class indicating there are more comments."""

def __init__(self, reddit, _data):
def __init__(self, reddit: Reddit, _data: Dict[str, Any]):
"""Construct an instance of the MoreComments object."""
self.count = self.parent_id = None
self.children = []
super().__init__(reddit, _data=_data)
self._comments = None
self.submission = None

def __eq__(self, other):
def __eq__(self, other: _MoreComments) -> bool:
"""Return True if these MoreComments instances are the same."""
return (
isinstance(other, self.__class__)
and self.count == other.count
and self.children == other.children
)

def __lt__(self, other):
def __lt__(self, other: _MoreComments) -> bool:
"""Provide a sort order on the MoreComments object."""
# To work with heapq a "smaller" item is the one with the most comments
# We are intentionally making the biggest element the smallest element
# to turn the min-heap implementation in heapq into a max-heap.
return self.count > other.count

def __repr__(self):
def __repr__(self) -> str:
"""Return a string representation of the MoreComments instance."""
children = self.children[:4]
if len(self.children) > 4:
Expand Down Expand Up @@ -61,7 +66,7 @@ def _load_comment(self, comment_id):
assert len(comments.children) == 1
return comments.children[0]

def comments(self, update=True):
def comments(self, update: bool = True) -> List[Comment]:
"""Fetch and return the comments for a single MoreComments object."""
if self._comments is None:
if self.count == 0: # Handle 'continue this thread'
Expand Down

0 comments on commit 932fab7

Please sign in to comment.