Skip to content

Commit

Permalink
Merge pull request #58 from praw-dev/cleanup
Browse files Browse the repository at this point in the history
Cleanup codebase
  • Loading branch information
LilSpazJoekp committed Feb 11, 2021
2 parents fe1bcb0 + c65819f commit 6ffafaa
Show file tree
Hide file tree
Showing 76 changed files with 707 additions and 618 deletions.
4 changes: 2 additions & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Maintainers
===========
Author/Maintainer
=================

- Joel Payne <lilspazjoekp@gmail.com> `@LilSpazJoekp <https://github.com/lilspazjoekp>`_

Expand Down
1 change: 0 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Unreleased

* First official Async PRAW release!


7.1.0.pre1 (2020/07/16)
-----------------------

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Async PRAW: The Asynchronous Python Reddit API Wrapper
:alt: Contributor Covenant
:target: https://github.com/praw-dev/asyncpraw/blob/master/CODE_OF_CONDUCT.md

Async PRAW, an acronym for "Asynchronous Python Reddit API Wrapper", is a Python package that
Async PRAW, an abbreviation for "Asynchronous Python Reddit API Wrapper", is a Python package that
allows for simple access to Reddit's API. Async PRAW aims to be easy to use and
internally follows all of `Reddit's API rules
<https://github.com/reddit/reddit/wiki/API>`_. With Async PRAW there's no need to
Expand Down Expand Up @@ -147,4 +147,4 @@ License
Async PRAW's source (v7.1.1+) is provided under the `Simplified BSD License
<https://github.com/praw-dev/asyncpraw/blob/30796acc29b4ba2335cf0eab414477702c29452f/LICENSE.txt>`_.

* Copyright (c), 2020, Joel Payne
* Copyright ©, 2020, Joel Payne
5 changes: 2 additions & 3 deletions asyncpraw/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Python Reddit API Wrapper.
"""Asynchronous Python Reddit API Wrapper.
Async PRAW, an acronym for "Asynchronous Python Reddit API Wrapper", is a python package that
Async PRAW, an abbreviation for "Asynchronous Python Reddit API Wrapper", is a python package that
allows for simple access to reddit's API. Async PRAW aims to be as easy to use as
possible and is designed to follow all of reddit's API rules. You have to give
a useragent, everything else is handled by Async PRAW so you needn't worry about
Expand Down
12 changes: 8 additions & 4 deletions asyncpraw/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def _load_config(cls, config_interpolation: Optional[str] = None):

@property
def short_url(self) -> str:
"""Return the short url or raise a ClientException when not set."""
"""Return the short url.
:raises: :class:`.ClientException` if it is not set.
"""
if self._short_url is self.CONFIG_NOT_SET:
raise ClientException("No short domain specified.")
return self._short_url
Expand Down Expand Up @@ -149,7 +153,7 @@ def _initialize_attributes(self):
setattr(self, attribute, conversion(getattr(self, attribute)))
except ValueError:
raise ValueError(
f"An incorrect config type was given for option {attribute}. The "
f"expected type is {conversion.__name__}, but the given value is "
f"{getattr(self, attribute)}."
f"An incorrect config type was given for option {attribute}. The"
f" expected type is {conversion.__name__}, but the given value is"
f" {getattr(self, attribute)}."
)
42 changes: 23 additions & 19 deletions asyncpraw/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""PRAW exception classes.
"""Async PRAW exception classes.
Includes two main exceptions: :class:`.RedditAPIException` for when something
goes wrong on the server side, and :class:`.ClientException` when something
Expand Down Expand Up @@ -32,7 +32,7 @@ def error_message(self) -> str:
return error_str

def __init__(self, error_type: str, message: str, field: Optional[str] = None):
"""Instantiate an error item.
"""Initialize an error item.
:param error_type: The error type set on Reddit's end.
:param message: The associated message for the error.
Expand All @@ -54,7 +54,10 @@ def __eq__(self, other: Union["RedditErrorItem", List[str]]):

def __repr__(self):
"""Return repr(self)."""
return f"{self.__class__.__name__}(error_type={self.error_type!r}, message={self.message!r}, field={self.field!r})"
return (
f"{self.__class__.__name__}(error_type={self.error_type!r},"
f" message={self.message!r}, field={self.field!r})"
)

def __str__(self):
"""Get the message returned from str(self)."""
Expand All @@ -65,6 +68,7 @@ class APIException(AsyncPRAWException):
"""Old class preserved for alias purposes.
.. deprecated:: 7.0
Class :class:`.APIException` has been deprecated in favor of
:class:`.RedditAPIException`. This class will be removed in Async PRAW 8.0.
"""
Expand Down Expand Up @@ -130,10 +134,10 @@ def field(self) -> str:

def _get_old_attr(self, attrname):
warn(
f"Accessing attribute ``{attrname}`` through APIException is deprecated. "
f"This behavior will be removed in Async PRAW 8.0. Check out "
f"https://praw.readthedocs.io/en/latest/package_info/praw7_migration.html "
f"to learn how to migrate your code.",
f"Accessing attribute ``{attrname}`` through APIException is deprecated."
" This behavior will be removed in Async PRAW 8.0. Check out"
" https://praw.readthedocs.io/en/latest/package_info/praw7_migration.html"
" to learn how to migrate your code.",
category=DeprecationWarning,
stacklevel=3,
)
Expand Down Expand Up @@ -184,16 +188,16 @@ class InvalidFlairTemplateID(ClientException):
def __init__(self, template_id: str):
"""Initialize the class."""
super().__init__(
f"The flair template id ``{template_id}`` is invalid. If you are trying "
f"to create a flair, please use the ``add`` method."
f"The flair template id ``{template_id}`` is invalid. If you are trying to"
" create a flair, please use the ``add`` method."
)


class InvalidImplicitAuth(ClientException):
"""Indicate exceptions where an implicit auth type is used incorrectly."""

def __init__(self):
"""Instantize the class."""
"""Initialize the class."""
super().__init__("Implicit authorization can only be used with installed apps.")


Expand Down Expand Up @@ -226,8 +230,8 @@ def __init__(self, maximum_size: int, actual: int):
self.maximum_size = maximum_size
self.actual = actual
super().__init__(
f"The media that you uploaded was too large (maximum size is "
f"{maximum_size} bytes, uploaded {actual} bytes)"
f"The media that you uploaded was too large (maximum size is {maximum_size}"
f" bytes, uploaded {actual} bytes)"
)


Expand All @@ -238,9 +242,9 @@ class WebSocketException(ClientException):
def original_exception(self) -> Exception:
"""Access the original_exception attribute (now deprecated)."""
warn(
"Accessing the attribute original_exception is deprecated. Please"
" rewrite your code in such a way that this attribute does not"
" need to be used. It will be removed in Async PRAW 8.0.",
"Accessing the attribute original_exception is deprecated. Please rewrite"
" your code in such a way that this attribute does not need to be used. It"
" will be removed in Async PRAW 8.0.",
category=DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -271,11 +275,11 @@ class MediaPostFailed(WebSocketException):
"""Indicate exceptions where media uploads failed.."""

def __init__(self):
"""Instantiate MediaPostFailed."""
"""Initialize MediaPostFailed."""
super().__init__(
"The attempted media upload action has failed. Possible causes"
" include the corruption of media files. Check that the media "
"file can be opened on your local machine.",
"The attempted media upload action has failed. Possible causes include the"
" corruption of media files. Check that the media file can be opened on"
" your local machine.",
None,
)

Expand Down
6 changes: 3 additions & 3 deletions asyncpraw/models/comment_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __getitem__(self, index: int):
first_comment = comments[0]
Alternatively, the presence of this method enables one to iterate over
all top_level comments, like so:
all top level comments, like so:
.. code-block:: python
Expand Down Expand Up @@ -103,8 +103,8 @@ def _insert_comment(self, comment):
self._comments.append(comment)
else:
assert comment.parent_id in self._submission._comments_by_id, (
"PRAW Error occurred. Please file a bug report and include "
"the code that caused the error."
"Async PRAW Error occurred. Please file a bug report and include the"
" code that caused the error."
)
parent = self._submission._comments_by_id[comment.parent_id]
parent.replies._comments.append(comment)
Expand Down
6 changes: 2 additions & 4 deletions asyncpraw/models/front.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Provide the Front class."""
from typing import TYPE_CHECKING, AsyncGenerator, Union
from typing import TYPE_CHECKING, AsyncIterator, Union
from urllib.parse import urljoin

from .listing.generator import ListingGenerator
Expand All @@ -18,9 +18,7 @@ def __init__(self, reddit: "Reddit"):
super().__init__(reddit, _data=None)
self._path = "/"

def best(
self, **generator_kwargs: Union[str, int]
) -> AsyncGenerator[Submission, None]:
def best(self, **generator_kwargs: Union[str, int]) -> AsyncIterator[Submission]:
"""Return a :class:`.ListingGenerator` for best items.
Additional keyword arguments are passed in the initialization of
Expand Down
5 changes: 3 additions & 2 deletions asyncpraw/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def info(self, ids: List[str]) -> AsyncGenerator[LiveThread, None]:
.. code-block:: python
ids = ["3rgnbke2rai6hen7ciytwcxadi",
"LiveUpdateEvent_sw7bubeycai6hey4ciytwamw3a",
"sw7bubeycai6hey4ciytwamw3a",
"t8jnufucss07"]
async for thread in reddit.live.info(ids):
Expand Down Expand Up @@ -252,7 +251,9 @@ async def create(
Any keyword parameters not provided, or set explicitly to None, will
take on a default value assigned by the Reddit server.
.. seealso:: :meth:`~.SubredditModeration.update` for documentation
.. seealso::
:meth:`~.SubredditModeration.update` for documentation
of other available settings.
"""
Expand Down
20 changes: 10 additions & 10 deletions asyncpraw/models/inbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Provide the Front class."""
from typing import TYPE_CHECKING, AsyncGenerator, Dict, List, Union
from typing import TYPE_CHECKING, AsyncIterator, Dict, List, Union

from ..const import API_PATH
from .base import AsyncPRAWBase
Expand All @@ -16,7 +16,7 @@ class Inbox(AsyncPRAWBase):

def all(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> AsyncGenerator[Union["Message", "Comment"], None]:
) -> AsyncIterator[Union["Message", "Comment"]]:
"""Return a :class:`.ListingGenerator` for all inbox comments and messages.
Additional keyword arguments are passed in the initialization of
Expand Down Expand Up @@ -62,7 +62,7 @@ async def collapse(self, items: List["Message"]):

def comment_replies(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> AsyncGenerator["Comment", None]:
) -> AsyncIterator["Comment"]:
"""Return a :class:`.ListingGenerator` for comment replies.
Additional keyword arguments are passed in the initialization of
Expand Down Expand Up @@ -138,11 +138,11 @@ async def mark_unread(self, items: List[Union["Comment", "Message"]]):

def mentions(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> AsyncGenerator["Comment", None]:
) -> AsyncIterator["Comment"]:
r"""Return a :class:`.ListingGenerator` for mentions.
A mention is :class:`.Comment` in which the authorized redditor is
named in its body like ``/u/redditor_name``.
named in its body like ``u/redditor_name``.
Additional keyword arguments are passed in the initialization of
:class:`.ListingGenerator`.
Expand Down Expand Up @@ -179,7 +179,7 @@ async def message(self, message_id: str) -> "Message":

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

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

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

def submission_replies(
self, **generator_kwargs: Union[str, int, Dict[str, str]]
) -> AsyncGenerator["Comment", None]:
) -> AsyncIterator["Comment"]:
"""Return a :class:`.ListingGenerator` for submission replies.
Additional keyword arguments are passed in the initialization of
Expand Down Expand Up @@ -286,7 +286,7 @@ def unread(
self,
mark_read: bool = False,
**generator_kwargs: Union[str, int, Dict[str, str]]
) -> AsyncGenerator[Union["Comment", "Message"], None]:
) -> AsyncIterator[Union["Comment", "Message"]]:
"""Return a :class:`.ListingGenerator` for unread comments and messages.
:param mark_read: Marks the inbox as read (default: False).
Expand Down
Loading

0 comments on commit 6ffafaa

Please sign in to comment.