Skip to content

Commit 75fa6c5

Browse files
authored
Merge pull request praw-dev#2053 from praw-dev/more_cleanup
Resolve a ton of additional ruff warnings
2 parents eed839c + 426d8a5 commit 75fa6c5

75 files changed

Lines changed: 838 additions & 801 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[report]
22
exclude_lines =
3-
@abstract
43
if TYPE_CHECKING:
54
pragma: no cover

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ Unreleased
1212

1313
**Changed**
1414

15-
- Bumped prawcore to 3.0.1.
15+
- Bumped prawcore to 3.0.2.
1616
- Drop support for Python 3.8, which was end-of-life on 2024-10-07.
1717
- Change ``Reddit.user.me`` to raise :class:`.ReadOnlyException` when called in
1818
:attr:`.read_only` mode.
1919
- The ``subreddit`` attribute of :class:`.Redditor` is a :class:`.UserSubreddit`
2020
instance.
21+
- The ``data`` argument to ``Objector.objectify`` must now be passed by keyword.
22+
- The ``mark_read`` argument to ``subreddit.modmail`` (:class:`.ModmailConversation`)
23+
must now be passed by keyword.
24+
- The ``flair_type`` argument to :class:`.SubredditFlairTemplates` must be passed by
25+
keyword.
2126

2227
**Removed**
2328

praw/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
1010
"""
1111

12-
from .const import __version__
13-
from .reddit import Reddit
12+
from praw.const import __version__
13+
from praw.reddit import Reddit

praw/config.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import os
99
from pathlib import Path
1010
from threading import Lock
11+
from types import MappingProxyType
1112
from typing import Any
1213

13-
from .exceptions import ClientException
14+
from praw.exceptions import ClientException
1415

1516

1617
class _NotSet:
@@ -29,19 +30,19 @@ class Config:
2930
CONFIG = None
3031
CONFIG_NOT_SET = _NotSet() # Represents a config value that is not set.
3132
LOCK = Lock()
32-
INTERPOLATION_LEVEL = {
33+
INTERPOLATION_LEVEL = MappingProxyType({
3334
"basic": configparser.BasicInterpolation,
3435
"extended": configparser.ExtendedInterpolation,
35-
}
36+
})
3637

3738
@staticmethod
38-
def _config_boolean(item: bool | str) -> bool:
39+
def _config_boolean(*, item: bool | str) -> bool:
3940
if isinstance(item, bool):
4041
return item
4142
return item.lower() in {"1", "yes", "true", "on"}
4243

4344
@classmethod
44-
def _load_config(cls, *, config_interpolation: str | None = None):
45+
def _load_config(cls, *, config_interpolation: str | None = None) -> None:
4546
"""Attempt to load settings from various praw.ini files."""
4647
if config_interpolation is not None:
4748
interpolator_class = cls.INTERPOLATION_LEVEL[config_interpolation]()
@@ -86,7 +87,7 @@ def __init__(
8687
site_name: str,
8788
config_interpolation: str | None = None,
8889
**settings: str,
89-
):
90+
) -> None:
9091
"""Initialize a :class:`.Config` instance."""
9192
with Config.LOCK:
9293
if Config.CONFIG is None:
@@ -121,13 +122,13 @@ def _fetch_or_not_set(self, key: str) -> Any | _NotSet:
121122
# Environment variables have higher priority than praw.ini settings
122123
return env_value or ini_value or self.CONFIG_NOT_SET
123124

124-
def _initialize_attributes(self):
125+
def _initialize_attributes(self) -> None:
125126
self._short_url = self._fetch_default("short_url") or self.CONFIG_NOT_SET
126-
self.check_for_async = self._config_boolean(self._fetch_default("check_for_async", default=True))
127-
self.check_for_updates = self._config_boolean(self._fetch_or_not_set("check_for_updates"))
128-
self.warn_comment_sort = self._config_boolean(self._fetch_default("warn_comment_sort", default=True))
127+
self.check_for_async = self._config_boolean(item=self._fetch_default("check_for_async", default=True))
128+
self.check_for_updates = self._config_boolean(item=self._fetch_or_not_set("check_for_updates"))
129+
self.warn_comment_sort = self._config_boolean(item=self._fetch_default("warn_comment_sort", default=True))
129130
self.warn_additional_fetch_params = self._config_boolean(
130-
self._fetch_default("warn_additional_fetch_params", default=True)
131+
item=self._fetch_default("warn_additional_fetch_params", default=True)
131132
)
132133
self.window_size = self._fetch_default("window_size", default=600)
133134
self.kinds = {

praw/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""PRAW constants."""
22

3-
from .endpoints import API_PATH # noqa: F401
3+
from praw.endpoints import API_PATH # noqa: F401
44

55
__version__ = "7.8.2.dev0"
66

praw/exceptions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from __future__ import annotations
1212

1313

14-
class PRAWException(Exception):
14+
class PRAWException(Exception): # noqa: N818
1515
"""The base PRAW Exception that all other exception classes extend."""
1616

1717

@@ -48,7 +48,7 @@ def __init__(
4848
*,
4949
field: str | None = None,
5050
message: str | None = None,
51-
):
51+
) -> None:
5252
"""Initialize a :class:`.RedditErrorItem` instance.
5353
5454
:param error_type: The error type set on Reddit's end.
@@ -78,7 +78,7 @@ class ClientException(PRAWException):
7878
class DuplicateReplaceException(ClientException):
7979
"""Indicate exceptions that involve the replacement of :class:`.MoreComments`."""
8080

81-
def __init__(self):
81+
def __init__(self) -> None:
8282
"""Initialize a :class:`.DuplicateReplaceException` instance."""
8383
super().__init__(
8484
"A duplicate comment has been detected. Are you attempting to call 'replace_more_comments' more than once?"
@@ -88,7 +88,7 @@ def __init__(self):
8888
class InvalidFlairTemplateID(ClientException):
8989
"""Indicate exceptions where an invalid flair template ID is given."""
9090

91-
def __init__(self, template_id: str):
91+
def __init__(self, template_id: str) -> None:
9292
"""Initialize an :class:`.InvalidFlairTemplateID` instance."""
9393
super().__init__(
9494
f"The flair template ID '{template_id}' is invalid. If you are trying to"
@@ -99,15 +99,15 @@ def __init__(self, template_id: str):
9999
class InvalidImplicitAuth(ClientException):
100100
"""Indicate exceptions where an implicit auth type is used incorrectly."""
101101

102-
def __init__(self):
102+
def __init__(self) -> None:
103103
"""Initialize an :class:`.InvalidImplicitAuth` instance."""
104104
super().__init__("Implicit authorization can only be used with installed apps.")
105105

106106

107107
class InvalidURL(ClientException):
108108
"""Indicate exceptions where an invalid URL is entered."""
109109

110-
def __init__(self, url: str, *, message: str = "Invalid URL: {}"):
110+
def __init__(self, url: str, *, message: str = "Invalid URL: {}") -> None:
111111
"""Initialize an :class:`.InvalidURL` instance.
112112
113113
:param url: The invalid URL.
@@ -129,7 +129,7 @@ class ReadOnlyException(ClientException):
129129
class TooLargeMediaException(ClientException):
130130
"""Indicate exceptions from uploading media that's too large."""
131131

132-
def __init__(self, *, actual: int, maximum_size: int):
132+
def __init__(self, *, actual: int, maximum_size: int) -> None:
133133
"""Initialize a :class:`.TooLargeMediaException` instance.
134134
135135
:param actual: The actual size of the uploaded media.
@@ -146,7 +146,7 @@ def __init__(self, *, actual: int, maximum_size: int):
146146
class WebSocketException(ClientException):
147147
"""Indicate exceptions caused by use of WebSockets."""
148148

149-
def __init__(self, message: str):
149+
def __init__(self, message: str) -> None:
150150
"""Initialize a :class:`.WebSocketException` instance.
151151
152152
:param message: The exception message.
@@ -158,7 +158,7 @@ def __init__(self, message: str):
158158
class MediaPostFailed(WebSocketException):
159159
"""Indicate exceptions where media uploads failed.."""
160160

161-
def __init__(self):
161+
def __init__(self) -> None:
162162
"""Initialize a :class:`.MediaPostFailed` instance."""
163163
super().__init__(
164164
"The attempted media upload action has failed. Possible causes include the"
@@ -188,7 +188,7 @@ def parse_exception_list(
188188
for exception in exceptions
189189
]
190190

191-
def __init__(self, items: list[RedditErrorItem | list[str] | str]):
191+
def __init__(self, items: list[RedditErrorItem | list[str] | str]) -> None:
192192
"""Initialize a :class:`.RedditAPIException` instance.
193193
194194
:param items: Either a list of instances of :class:`.RedditErrorItem` or a list

praw/models/__init__.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
"""Provide the PRAW models."""
22

3-
from .auth import Auth
4-
from .front import Front
5-
from .helpers import DraftHelper, LiveHelper, MultiredditHelper, SubredditHelper
6-
from .inbox import Inbox
7-
from .list.draft import DraftList
8-
from .list.moderated import ModeratedList
9-
from .list.redditor import RedditorList
10-
from .list.trophy import TrophyList
11-
from .listing.domain import DomainListing
12-
from .listing.generator import ListingGenerator
13-
from .listing.listing import Listing, ModeratorListing, ModmailConversationsListing
14-
from .mod_action import ModAction
15-
from .mod_note import ModNote
16-
from .mod_notes import RedditModNotes, RedditorModNotes, SubredditModNotes
17-
from .preferences import Preferences
18-
from .reddit.collections import Collection
19-
from .reddit.comment import Comment
20-
from .reddit.draft import Draft
21-
from .reddit.emoji import Emoji
22-
from .reddit.inline_media import InlineGif, InlineImage, InlineMedia, InlineVideo
23-
from .reddit.live import LiveThread, LiveUpdate
24-
from .reddit.message import Message, SubredditMessage
25-
from .reddit.modmail import ModmailAction, ModmailConversation, ModmailMessage
26-
from .reddit.more import MoreComments
27-
from .reddit.multi import Multireddit
28-
from .reddit.poll import PollData, PollOption
29-
from .reddit.redditor import Redditor
30-
from .reddit.removal_reasons import RemovalReason
31-
from .reddit.rules import Rule
32-
from .reddit.submission import Submission
33-
from .reddit.subreddit import Subreddit
34-
from .reddit.user_subreddit import UserSubreddit
35-
from .reddit.widgets import (
3+
from praw.models.auth import Auth
4+
from praw.models.front import Front
5+
from praw.models.helpers import DraftHelper, LiveHelper, MultiredditHelper, SubredditHelper
6+
from praw.models.inbox import Inbox
7+
from praw.models.list.draft import DraftList
8+
from praw.models.list.moderated import ModeratedList
9+
from praw.models.list.redditor import RedditorList
10+
from praw.models.list.trophy import TrophyList
11+
from praw.models.listing.domain import DomainListing
12+
from praw.models.listing.generator import ListingGenerator
13+
from praw.models.listing.listing import Listing, ModeratorListing, ModmailConversationsListing
14+
from praw.models.mod_action import ModAction
15+
from praw.models.mod_note import ModNote
16+
from praw.models.mod_notes import RedditModNotes, RedditorModNotes, SubredditModNotes
17+
from praw.models.preferences import Preferences
18+
from praw.models.reddit.collections import Collection
19+
from praw.models.reddit.comment import Comment
20+
from praw.models.reddit.draft import Draft
21+
from praw.models.reddit.emoji import Emoji
22+
from praw.models.reddit.inline_media import InlineGif, InlineImage, InlineMedia, InlineVideo
23+
from praw.models.reddit.live import LiveThread, LiveUpdate
24+
from praw.models.reddit.message import Message, SubredditMessage
25+
from praw.models.reddit.modmail import ModmailAction, ModmailConversation, ModmailMessage
26+
from praw.models.reddit.more import MoreComments
27+
from praw.models.reddit.multi import Multireddit
28+
from praw.models.reddit.poll import PollData, PollOption
29+
from praw.models.reddit.redditor import Redditor
30+
from praw.models.reddit.removal_reasons import RemovalReason
31+
from praw.models.reddit.rules import Rule
32+
from praw.models.reddit.submission import Submission
33+
from praw.models.reddit.subreddit import Subreddit
34+
from praw.models.reddit.user_subreddit import UserSubreddit
35+
from praw.models.reddit.widgets import (
3636
Button,
3737
ButtonWidget,
3838
Calendar,
@@ -57,9 +57,9 @@
5757
Widget,
5858
WidgetModeration,
5959
)
60-
from .reddit.wikipage import WikiPage
61-
from .redditors import Redditors
62-
from .stylesheet import Stylesheet
63-
from .subreddits import Subreddits
64-
from .trophy import Trophy
65-
from .user import User
60+
from praw.models.reddit.wikipage import WikiPage
61+
from praw.models.redditors import Redditors
62+
from praw.models.stylesheet import Stylesheet
63+
from praw.models.subreddits import Subreddits
64+
from praw.models.trophy import Trophy
65+
from praw.models.user import User

praw/models/auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from prawcore import Authorizer, ImplicitAuthorizer, UntrustedAuthenticator, session
66

7-
from ..exceptions import InvalidImplicitAuth, MissingRequiredAttributeException
8-
from .base import PRAWBase
7+
from praw.exceptions import InvalidImplicitAuth, MissingRequiredAttributeException
8+
from praw.models.base import PRAWBase
99

1010

1111
class Auth(PRAWBase):
@@ -48,7 +48,7 @@ def authorize(self, code: str) -> str | None:
4848
self._reddit._core = self._reddit._authorized_core = authorized_session
4949
return authorizer.refresh_token
5050

51-
def implicit(self, *, access_token: str, expires_in: int, scope: str):
51+
def implicit(self, *, access_token: str, expires_in: int, scope: str) -> None:
5252
"""Set the active authorization to be an implicit authorization.
5353
5454
:param access_token: The access_token obtained from Reddit's callback.

praw/models/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from copy import deepcopy
66
from typing import TYPE_CHECKING, Any
77

8-
if TYPE_CHECKING: # pragma: no cover
8+
if TYPE_CHECKING:
99
import praw
1010

1111

1212
class PRAWBase:
1313
"""Superclass for all models in PRAW."""
1414

1515
@staticmethod
16-
def _safely_add_arguments(*, arguments: dict[str, Any], key: str, **new_arguments: Any):
16+
def _safely_add_arguments(*, arguments: dict[str, Any], key: str, **new_arguments: Any) -> None:
1717
"""Replace arguments[key] with a deepcopy and update.
1818
1919
This method is often called when new parameters need to be added to a request.
@@ -35,7 +35,7 @@ def parse(cls, data: dict[str, Any], reddit: praw.Reddit) -> Any:
3535
"""
3636
return cls(reddit, _data=data)
3737

38-
def __init__(self, reddit: praw.Reddit, _data: dict[str, Any] | None):
38+
def __init__(self, reddit: praw.Reddit, _data: dict[str, Any] | None) -> None:
3939
"""Initialize a :class:`.PRAWBase` instance.
4040
4141
:param reddit: An instance of :class:`.Reddit`.

praw/models/comment_forest.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from heapq import heappop, heappush
66
from typing import TYPE_CHECKING
77

8-
from ..exceptions import DuplicateReplaceException
9-
from .reddit.more import MoreComments
8+
from praw.exceptions import DuplicateReplaceException
9+
from praw.models.reddit.more import MoreComments
1010

11-
if TYPE_CHECKING: # pragma: no cover
11+
if TYPE_CHECKING:
1212
import praw.models
1313

1414

@@ -43,7 +43,7 @@ def __len__(self) -> int:
4343
"""Return the number of top-level comments in the forest."""
4444
return len(self._comments)
4545

46-
def _insert_comment(self, comment: praw.models.Comment):
46+
def _insert_comment(self, comment: praw.models.Comment) -> None:
4747
if comment.name in self._submission._comments_by_id:
4848
raise DuplicateReplaceException
4949
comment.submission = self._submission
@@ -56,7 +56,7 @@ def _insert_comment(self, comment: praw.models.Comment):
5656
parent = self._submission._comments_by_id[comment.parent_id]
5757
parent.replies._comments.append(comment)
5858

59-
def list( # noqa: A003
59+
def list(
6060
self,
6161
) -> list[praw.models.Comment | praw.models.MoreComments]:
6262
"""Return a flattened list of all comments.
@@ -100,7 +100,7 @@ def __init__(
100100
self,
101101
submission: praw.models.Submission,
102102
comments: list[praw.models.Comment] | None = None,
103-
):
103+
) -> None:
104104
"""Initialize a :class:`.CommentForest` instance.
105105
106106
:param submission: An instance of :class:`.Submission` that is the parent of the
@@ -112,7 +112,7 @@ def __init__(
112112
self._comments = comments
113113
self._submission = submission
114114

115-
def _update(self, comments: list[praw.models.Comment]):
115+
def _update(self, comments: list[praw.models.Comment]) -> None:
116116
self._comments = comments
117117
for comment in comments:
118118
comment.submission = self._submission
@@ -179,7 +179,7 @@ def replace_more(self, *, limit: int | None = 32, threshold: int = 0) -> list[pr
179179
# Fetch largest more_comments until reaching the limit or the threshold
180180
while more_comments:
181181
item = heappop(more_comments)
182-
if remaining is not None and remaining <= 0 or item.count < threshold:
182+
if (remaining is not None and remaining <= 0) or item.count < threshold:
183183
skipped.append(item)
184184
item._remove_from.remove(item)
185185
continue

0 commit comments

Comments
 (0)