Skip to content

Commit

Permalink
Merge pull request #1046 from Pyprohly/tweaks
Browse files Browse the repository at this point in the history
Minor syntactic tweaks
  • Loading branch information
bboe committed Mar 24, 2019
2 parents dba778a + 71c4ff3 commit 9287b26
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 118 deletions.
8 changes: 2 additions & 6 deletions praw/const.py
Expand Up @@ -124,9 +124,7 @@
"quarantine_opt_in": "api/quarantine_optin",
"quarantine_opt_out": "api/quarantine_optout",
"read_message": "api/read_message/",
(
"removal_comment_" "message"
): "api/v1/modactions/removal_comment_message",
"removal_comment_message": "api/v1/modactions/removal_comment_message",
"removal_link_message": "api/v1/modactions/removal_link_message",
"remove": "api/remove/",
"report": "api/report/",
Expand All @@ -149,9 +147,7 @@
"submit": "api/submit/",
"subreddit": "r/{subreddit}/",
"subreddit_about": "r/{subreddit}/about/",
"subreddit_filter": (
"api/filter/user/{user}/f/{special}/" "r/{subreddit}"
),
"subreddit_filter": "api/filter/user/{user}/f/{special}/r/{subreddit}",
"subreddit_filter_list": "api/filter/user/{user}/f/{special}",
"subreddit_random": "r/{subreddit}/random/",
"subreddit_settings": "r/{subreddit}/about/edit/",
Expand Down
49 changes: 1 addition & 48 deletions praw/models/__init__.py
Expand Up @@ -50,51 +50,4 @@
from .trophy import Trophy
from .user import User

__all__ = (
"Auth",
"Button",
"ButtonWidget",
"Calendar",
"Comment",
"CommunityList",
"CustomWidget",
"DomainListing",
"Emoji",
"Front",
"IDCard",
"Image",
"ImageData",
"ImageWidget",
"Inbox",
"Listing",
"ListingGenerator",
"LiveHelper",
"LiveThread",
"Menu",
"MenuLink",
"Message",
"ModAction",
"ModeratorsWidget",
"ModmailConversation",
"MoreComments",
"Multireddit",
"MultiredditHelper",
"PostFlairWidget",
"Preferences",
"Redditor",
"RedditorList",
"Redditors",
"RulesWidget",
"Stylesheet",
"Submenu",
"Submission",
"Subreddit",
"SubredditHelper",
"SubredditMessage",
"SubredditWidgets",
"TrophyList",
"User",
"Widget",
"WidgetModeration",
"WikiPage",
)
__all__ = [n for n in globals().keys() if n[:1] != "_"]
4 changes: 2 additions & 2 deletions praw/models/auth.py
Expand Up @@ -77,7 +77,7 @@ def implicit(self, access_token, expires_in, scope):
authenticator = self._reddit._read_only_core._authorizer._authenticator
if not isinstance(authenticator, UntrustedAuthenticator):
raise ClientException(
"implicit can only be used with installed " "apps."
"implicit can only be used with installed apps."
)
implicit_session = session(
ImplicitAuthorizer(authenticator, access_token, expires_in, scope)
Expand Down Expand Up @@ -126,6 +126,6 @@ def url(self, scopes, state, duration="permanent", implicit=False):
)
if implicit:
raise ClientException(
"implicit can only be set for installed " "applications"
"implicit can only be set for installed applications"
)
return authenticator.authorize_url(duration, scopes, state)
2 changes: 1 addition & 1 deletion praw/models/list/base.py
Expand Up @@ -13,7 +13,7 @@ def __init__(self, reddit, _data):
:param reddit: An instance of :class:`~.Reddit`.
"""
super(BaseList, self).__init__(reddit, _data)
super(BaseList, self).__init__(reddit, _data=_data)

if self.CHILD_ATTRIBUTE is None:
raise NotImplementedError("BaseList must be extended.")
Expand Down
2 changes: 1 addition & 1 deletion praw/models/listing/mixins/subreddit.py
Expand Up @@ -35,7 +35,7 @@ def __init__(self, reddit, _data):
:param reddit: An instance of :class:`.Reddit`.
"""
super(SubredditListingMixin, self).__init__(reddit, _data)
super(SubredditListingMixin, self).__init__(reddit, _data=_data)
self._comments = None


Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/base.py
Expand Up @@ -62,7 +62,7 @@ def __init__(self, reddit, _data):
:param reddit: An instance of :class:`~.Reddit`.
"""
super(RedditBase, self).__init__(reddit, _data)
super(RedditBase, self).__init__(reddit, _data=_data)
self._fetched = False
self._info_params = {}

Expand Down
8 changes: 4 additions & 4 deletions praw/models/reddit/comment.py
Expand Up @@ -6,7 +6,7 @@
from .redditor import Redditor


class Comment(RedditBase, InboxableMixin, UserContentMixin):
class Comment(InboxableMixin, UserContentMixin, RedditBase):
"""A class that represents a reddit comments.
**Typical Attributes**
Expand Down Expand Up @@ -50,7 +50,7 @@ class Comment(RedditBase, InboxableMixin, UserContentMixin):
"""

MISSING_COMMENT_MESSAGE = (
"This comment does not appear to be in the " "comment tree"
"This comment does not appear to be in the comment tree"
)
STR_FIELD = "id"

Expand Down Expand Up @@ -130,10 +130,10 @@ def __init__(
"""Construct an instance of the Comment object."""
if [id, url, _data].count(None) != 2:
raise TypeError(
"Exactly one of `id`, `url`, or `_data` must be " "provided."
"Exactly one of `id`, `url`, or `_data` must be provided."
)
self._mod = self._replies = self._submission = None
super(Comment, self).__init__(reddit, _data)
super(Comment, self).__init__(reddit, _data=_data)
if id:
self.id = id # pylint: disable=invalid-name
elif url:
Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/emoji.py
Expand Up @@ -49,7 +49,7 @@ def __init__(self, reddit, subreddit, name, _data=None):
"""Construct an instance of the Emoji object."""
self.name = name
self.subreddit = subreddit
super(Emoji, self).__init__(reddit, _data)
super(Emoji, self).__init__(reddit, _data=_data)

def _fetch(self):
for emoji in self.subreddit.emoji:
Expand Down
4 changes: 2 additions & 2 deletions praw/models/reddit/live.py
Expand Up @@ -346,7 +346,7 @@ def __init__(
"""
if bool(id) == bool(_data):
raise TypeError("Either `id` or `_data` must be provided.")
super(LiveThread, self).__init__(reddit, _data)
super(LiveThread, self).__init__(reddit, _data=_data)
if id:
self.id = id # pylint: disable=invalid-name
self._contrib = None
Expand Down Expand Up @@ -605,7 +605,7 @@ def __init__(self, reddit, thread_id=None, update_id=None, _data=None):
# Since _data (part of JSON returned from reddit) have no
# thread ID, self._thread must be set by the caller of
# LiveUpdate(). See the code of LiveThread.updates() for example.
super(LiveUpdate, self).__init__(reddit, _data)
super(LiveUpdate, self).__init__(reddit, _data=_data)
self._fetched = True
elif thread_id and update_id:
super(LiveUpdate, self).__init__(reddit, None)
Expand Down
4 changes: 2 additions & 2 deletions praw/models/reddit/message.py
Expand Up @@ -6,7 +6,7 @@
from .subreddit import Subreddit


class Message(RedditBase, InboxableMixin, ReplyableMixin):
class Message(InboxableMixin, ReplyableMixin, RedditBase):
"""A class for private messages.
**Typical Attributes**
Expand Down Expand Up @@ -73,7 +73,7 @@ def parse(cls, data, reddit):

def __init__(self, reddit, _data):
"""Construct an instance of the Message object."""
super(Message, self).__init__(reddit, _data)
super(Message, self).__init__(reddit, _data=_data)
self._fetched = True

def delete(self):
Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/modmail.py
Expand Up @@ -135,7 +135,7 @@ def __init__(
(default: False).
"""
super(ModmailConversation, self).__init__(reddit, _data)
super(ModmailConversation, self).__init__(reddit, _data=_data)
if bool(id) == bool(_data):
raise TypeError("Either `id` or `_data` must be provided.")

Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/more.py
Expand Up @@ -10,7 +10,7 @@ def __init__(self, reddit, _data):
"""Construct an instance of the MoreComments object."""
self.count = self.parent_id = None
self.children = []
super(MoreComments, self).__init__(reddit, _data)
super(MoreComments, self).__init__(reddit, _data=_data)
self._comments = None
self.submission = None

Expand Down
4 changes: 2 additions & 2 deletions praw/models/reddit/multi.py
Expand Up @@ -9,7 +9,7 @@
from .subreddit import Subreddit, SubredditStream


class Multireddit(RedditBase, SubredditListingMixin):
class Multireddit(SubredditListingMixin, RedditBase):
r"""A class for users' Multireddits.
**Typical Attributes**
Expand Down Expand Up @@ -93,7 +93,7 @@ def stream(self):
def __init__(self, reddit, _data):
"""Construct an instance of the Multireddit object."""
self.path = None
super(Multireddit, self).__init__(reddit, _data)
super(Multireddit, self).__init__(reddit, _data=_data)
self._author = Redditor(reddit, self.path.split("/", 3)[2])
self._path = API_PATH["multireddit"].format(
multi=self.name, user=self._author
Expand Down
4 changes: 2 additions & 2 deletions praw/models/reddit/redditor.py
Expand Up @@ -8,7 +8,7 @@
from .mixins import MessageableMixin


class Redditor(RedditBase, MessageableMixin, RedditorListingMixin):
class Redditor(MessageableMixin, RedditorListingMixin, RedditBase):
"""A class representing the users of reddit.
**Typical Attributes**
Expand Down Expand Up @@ -109,7 +109,7 @@ def __init__(self, reddit, name=None, _data=None):
assert (
isinstance(_data, dict) and "name" in _data
), "Please file a bug with PRAW"
super(Redditor, self).__init__(reddit, _data)
super(Redditor, self).__init__(reddit, _data=_data)
self._listing_use_sort = True
if name:
self.name = name
Expand Down
6 changes: 3 additions & 3 deletions praw/models/reddit/submission.py
Expand Up @@ -9,7 +9,7 @@
from .subreddit import Subreddit


class Submission(RedditBase, SubmissionListingMixin, UserContentMixin):
class Submission(SubmissionListingMixin, UserContentMixin, RedditBase):
"""A class for submissions to reddit.
**Typical Attributes**
Expand Down Expand Up @@ -180,9 +180,9 @@ def __init__(
"""
if [id, url, _data].count(None) != 2:
raise TypeError(
"Exactly one of `id`, `url`, or `_data` must be " "provided."
"Exactly one of `id`, `url`, or `_data` must be provided."
)
super(Submission, self).__init__(reddit, _data)
super(Submission, self).__init__(reddit, _data=_data)
self.comment_limit = 2048

#: Specify the sort order for ``comments``
Expand Down
24 changes: 10 additions & 14 deletions praw/models/reddit/subreddit.py
Expand Up @@ -20,7 +20,7 @@
from .wikipage import WikiPage


class Subreddit(RedditBase, MessageableMixin, SubredditListingMixin):
class Subreddit(MessageableMixin, SubredditListingMixin, RedditBase):
"""A class for Subreddits.
To obtain an instance of this class for subreddit ``/r/redditdev`` execute:
Expand Down Expand Up @@ -430,7 +430,7 @@ def __init__(self, reddit, display_name=None, _data=None):
raise TypeError(
"Either `display_name` or `_data` must be provided."
)
super(Subreddit, self).__init__(reddit, _data)
super(Subreddit, self).__init__(reddit, _data=_data)
if display_name:
self.display_name = display_name
self._banned = self._contributor = self._filters = self._flair = None
Expand Down Expand Up @@ -473,7 +473,7 @@ def _submit_media(self, data, timeout):

if not isinstance(response, dict):
raise ClientException(
"Something went wrong with your post: " "{!r}".format(response)
"Something went wrong with your post: {!r}".format(response)
)

try:
Expand Down Expand Up @@ -2459,15 +2459,12 @@ def _upload_image(self, image_path, data):
return response

def _upload_style_asset(self, image_path, image_type):
data = {}
data["imagetype"] = image_type
data["filepath"] = basename(image_path)
data = {"imagetype": image_type, "filepath": basename(image_path)}
data["mimetype"] = "image/jpeg"
if image_path.lower().endswith(".png"):
data["mimetype"] = "image/png"
url = API_PATH["style_asset_lease"].format(subreddit=self.subreddit)

# until we learn otherwise, assume this request always succeeds
upload_lease = self.subreddit._reddit.post(url, data=data)[
"s3UploadLease"
]
Expand Down Expand Up @@ -2496,8 +2493,7 @@ def delete_banner(self):
reddit.subreddit('SUBREDDIT').stylesheet.delete_banner()
"""
data = {}
data["bannerBackgroundImage"] = ""
data = {"bannerBackgroundImage": ""}
self._update_structured_styles(data)

def delete_banner_additional_image(self):
Expand All @@ -2513,9 +2509,10 @@ def delete_banner_additional_image(self):
reddit.subreddit('SUBREDDIT').stylesheet.delete_banner_additional_image()
"""
data = {}
data["bannerPositionedImage"] = ""
data["secondaryBannerPositionedImage"] = ""
data = {
"bannerPositionedImage": "",
"secondaryBannerPositionedImage": "",
}
self._update_structured_styles(data)

def delete_banner_hover_image(self):
Expand All @@ -2530,8 +2527,7 @@ def delete_banner_hover_image(self):
reddit.subreddit('SUBREDDIT').stylesheet.delete_banner_hover_image()
"""
data = {}
data["secondaryBannerPositionedImage"] = ""
data = {"secondaryBannerPositionedImage": ""}
self._update_structured_styles(data)

def delete_header(self):
Expand Down
8 changes: 4 additions & 4 deletions praw/models/reddit/widgets.py
Expand Up @@ -948,7 +948,7 @@ def __init__(self, reddit, _data):
"""Initialize an instance of the class."""
self.subreddit = "" # in case it isn't in _data
self.id = "" # in case it isn't in _data
super(Widget, self).__init__(reddit, _data)
super(Widget, self).__init__(reddit, _data=_data)
self._mod = None


Expand Down Expand Up @@ -1268,7 +1268,7 @@ def __init__(self, reddit, _data):
_data["imageData"] = [
ImageData(reddit, data) for data in _data.pop("imageData")
]
super(CustomWidget, self).__init__(reddit, _data)
super(CustomWidget, self).__init__(reddit, _data=_data)


class IDCard(Widget):
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def __init__(self, reddit, _data):
if self.CHILD_ATTRIBUTE not in _data:
# .mod.update() sometimes returns payload without 'mods' field
_data[self.CHILD_ATTRIBUTE] = []
super(ModeratorsWidget, self).__init__(reddit, _data)
super(ModeratorsWidget, self).__init__(reddit, _data=_data)


class PostFlairWidget(Widget, BaseList):
Expand Down Expand Up @@ -1648,7 +1648,7 @@ def __init__(self, reddit, _data):
if self.CHILD_ATTRIBUTE not in _data:
# .mod.update() sometimes returns payload without 'data' field
_data[self.CHILD_ATTRIBUTE] = []
super(RulesWidget, self).__init__(reddit, _data)
super(RulesWidget, self).__init__(reddit, _data=_data)


class TextArea(Widget):
Expand Down
2 changes: 1 addition & 1 deletion praw/models/reddit/wikipage.py
Expand Up @@ -73,7 +73,7 @@ def __init__(self, reddit, subreddit, name, revision=None, _data=None):
self.name = name
self._revision = revision
self.subreddit = subreddit
super(WikiPage, self).__init__(reddit, _data)
super(WikiPage, self).__init__(reddit, _data=_data)
self._mod = None

def __repr__(self):
Expand Down

0 comments on commit 9287b26

Please sign in to comment.