Skip to content

Commit 37984c5

Browse files
committed
Add additional ruff checks and run autofix
autofixed via: ruff check --fix --unsafe-fixes ruff format
1 parent eed839c commit 37984c5

59 files changed

Lines changed: 472 additions & 435 deletions

Some content is hidden

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

praw/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _config_boolean(item: bool | str) -> bool:
4141
return item.lower() in {"1", "yes", "true", "on"}
4242

4343
@classmethod
44-
def _load_config(cls, *, config_interpolation: str | None = None):
44+
def _load_config(cls, *, config_interpolation: str | None = None) -> None:
4545
"""Attempt to load settings from various praw.ini files."""
4646
if config_interpolation is not None:
4747
interpolator_class = cls.INTERPOLATION_LEVEL[config_interpolation]()
@@ -86,7 +86,7 @@ def __init__(
8686
site_name: str,
8787
config_interpolation: str | None = None,
8888
**settings: str,
89-
):
89+
) -> None:
9090
"""Initialize a :class:`.Config` instance."""
9191
with Config.LOCK:
9292
if Config.CONFIG is None:
@@ -121,7 +121,7 @@ def _fetch_or_not_set(self, key: str) -> Any | _NotSet:
121121
# Environment variables have higher priority than praw.ini settings
122122
return env_value or ini_value or self.CONFIG_NOT_SET
123123

124-
def _initialize_attributes(self):
124+
def _initialize_attributes(self) -> None:
125125
self._short_url = self._fetch_default("short_url") or self.CONFIG_NOT_SET
126126
self.check_for_async = self._config_boolean(self._fetch_default("check_for_async", default=True))
127127
self.check_for_updates = self._config_boolean(self._fetch_or_not_set("check_for_updates"))

praw/exceptions.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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/auth.py

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

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

7-
from ..exceptions import InvalidImplicitAuth, MissingRequiredAttributeException
7+
from praw.exceptions import InvalidImplicitAuth, MissingRequiredAttributeException
8+
89
from .base import PRAWBase
910

1011

@@ -48,7 +49,7 @@ def authorize(self, code: str) -> str | None:
4849
self._reddit._core = self._reddit._authorized_core = authorized_session
4950
return authorizer.refresh_token
5051

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

praw/models/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from heapq import heappop, heappush
66
from typing import TYPE_CHECKING
77

8-
from ..exceptions import DuplicateReplaceException
8+
from praw.exceptions import DuplicateReplaceException
9+
910
from .reddit.more import MoreComments
1011

1112
if TYPE_CHECKING: # pragma: no cover
@@ -43,7 +44,7 @@ def __len__(self) -> int:
4344
"""Return the number of top-level comments in the forest."""
4445
return len(self._comments)
4546

46-
def _insert_comment(self, comment: praw.models.Comment):
47+
def _insert_comment(self, comment: praw.models.Comment) -> None:
4748
if comment.name in self._submission._comments_by_id:
4849
raise DuplicateReplaceException
4950
comment.submission = self._submission
@@ -56,7 +57,7 @@ def _insert_comment(self, comment: praw.models.Comment):
5657
parent = self._submission._comments_by_id[comment.parent_id]
5758
parent.replies._comments.append(comment)
5859

59-
def list( # noqa: A003
60+
def list(
6061
self,
6162
) -> list[praw.models.Comment | praw.models.MoreComments]:
6263
"""Return a flattened list of all comments.
@@ -100,7 +101,7 @@ def __init__(
100101
self,
101102
submission: praw.models.Submission,
102103
comments: list[praw.models.Comment] | None = None,
103-
):
104+
) -> None:
104105
"""Initialize a :class:`.CommentForest` instance.
105106
106107
:param submission: An instance of :class:`.Submission` that is the parent of the
@@ -112,7 +113,7 @@ def __init__(
112113
self._comments = comments
113114
self._submission = submission
114115

115-
def _update(self, comments: list[praw.models.Comment]):
116+
def _update(self, comments: list[praw.models.Comment]) -> None:
116117
self._comments = comments
117118
for comment in comments:
118119
comment.submission = self._submission
@@ -179,7 +180,7 @@ def replace_more(self, *, limit: int | None = 32, threshold: int = 0) -> list[pr
179180
# Fetch largest more_comments until reaching the limit or the threshold
180181
while more_comments:
181182
item = heappop(more_comments)
182-
if remaining is not None and remaining <= 0 or item.count < threshold:
183+
if (remaining is not None and remaining <= 0) or item.count < threshold:
183184
skipped.append(item)
184185
item._remove_from.remove(item)
185186
continue

praw/models/front.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class Front(SubredditListingMixin):
1818
"""Front is a Listing class that represents the front page."""
1919

20-
def __init__(self, reddit: praw.Reddit):
20+
def __init__(self, reddit: praw.Reddit) -> None:
2121
"""Initialize a :class:`.Front` instance."""
2222
super().__init__(reddit, _data=None)
2323
self._path = "/"

praw/models/helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from json import dumps
66
from typing import TYPE_CHECKING, Any
77

8-
from ..const import API_PATH
8+
from praw.const import API_PATH
9+
910
from .base import PRAWBase
1011
from .reddit.draft import Draft
1112
from .reddit.live import LiveThread
@@ -156,7 +157,7 @@ def create(
156157
*,
157158
description: str | None = None,
158159
nsfw: bool = False,
159-
resources: str = None,
160+
resources: str | None = None,
160161
) -> praw.models.LiveThread:
161162
"""Create a new :class:`.LiveThread`.
162163

praw/models/inbox.py

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

55
from typing import TYPE_CHECKING
66

7-
from ..const import API_PATH
7+
from praw.const import API_PATH
8+
89
from .base import PRAWBase
910
from .listing.generator import ListingGenerator
1011
from .util import stream_generator
@@ -18,7 +19,7 @@
1819
class Inbox(PRAWBase):
1920
"""Inbox is a Listing class that represents the inbox."""
2021

21-
def all( # noqa: A003
22+
def all(
2223
self, **generator_kwargs: str | int | dict[str, str]
2324
) -> Iterator[praw.models.Message | praw.models.Comment]:
2425
"""Return a :class:`.ListingGenerator` for all inbox comments and messages.
@@ -36,7 +37,7 @@ def all( # noqa: A003
3637
"""
3738
return ListingGenerator(self._reddit, API_PATH["inbox"], **generator_kwargs)
3839

39-
def collapse(self, items: list[praw.models.Message]):
40+
def collapse(self, items: list[praw.models.Message]) -> None:
4041
"""Mark an inbox message as collapsed.
4142
4243
:param items: A list containing instances of :class:`.Message`.
@@ -81,7 +82,7 @@ def comment_replies(self, **generator_kwargs: str | int | dict[str, str]) -> Ite
8182
"""
8283
return ListingGenerator(self._reddit, API_PATH["comment_replies"], **generator_kwargs)
8384

84-
def mark_all_read(self):
85+
def mark_all_read(self) -> None:
8586
"""Mark all messages as read with just one API call.
8687
8788
Example usage:
@@ -98,7 +99,7 @@ def mark_all_read(self):
9899
"""
99100
self._reddit.post(API_PATH["read_all_messages"])
100101

101-
def mark_read(self, items: list[praw.models.Comment | praw.models.Message]):
102+
def mark_read(self, items: list[praw.models.Comment | praw.models.Message]) -> None:
102103
"""Mark Comments or Messages as read.
103104
104105
:param items: A list containing instances of :class:`.Comment` and/or
@@ -130,7 +131,7 @@ def mark_read(self, items: list[praw.models.Comment | praw.models.Message]):
130131
self._reddit.post(API_PATH["read_message"], data=data)
131132
items = items[25:]
132133

133-
def mark_unread(self, items: list[praw.models.Comment | praw.models.Message]):
134+
def mark_unread(self, items: list[praw.models.Comment | praw.models.Message]) -> None:
134135
"""Unmark Comments or Messages as read.
135136
136137
:param items: A list containing instances of :class:`.Comment` and/or
@@ -189,7 +190,7 @@ def message(self, message_id: str) -> praw.models.Message:
189190
190191
"""
191192
listing = self._reddit.get(API_PATH["message"].format(id=message_id))
192-
messages = {message.fullname: message for message in [listing[0]] + listing[0].replies}
193+
messages = {message.fullname: message for message in [listing[0], *listing[0].replies]}
193194
for _fullname, message in messages.items():
194195
message.parent = messages.get(message.parent_id, None)
195196
return messages[f"t4_{message_id.lower()}"]
@@ -262,7 +263,7 @@ def submission_replies(self, **generator_kwargs: str | int | dict[str, str]) ->
262263
"""
263264
return ListingGenerator(self._reddit, API_PATH["submission_replies"], **generator_kwargs)
264265

265-
def uncollapse(self, items: list[praw.models.Message]):
266+
def uncollapse(self, items: list[praw.models.Message]) -> None:
266267
"""Mark an inbox message as uncollapsed.
267268
268269
:param items: A list containing instances of :class:`.Message`.

praw/models/list/base.py

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

55
from typing import TYPE_CHECKING, Any
66

7-
from ..base import PRAWBase
7+
from praw.models.base import PRAWBase
88

99
if TYPE_CHECKING: # pragma: no cover
1010
from collections.abc import Iterator
@@ -25,7 +25,7 @@ def __getitem__(self, index: int) -> Any:
2525
"""Return the item at position index in the list."""
2626
return getattr(self, self.CHILD_ATTRIBUTE)[index]
2727

28-
def __init__(self, reddit: praw.Reddit, _data: dict[str, Any]):
28+
def __init__(self, reddit: praw.Reddit, _data: dict[str, Any]) -> None:
2929
"""Initialize a :class:`.BaseList` instance.
3030
3131
:param reddit: An instance of :class:`.Reddit`.

praw/models/listing/domain.py

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

55
from typing import TYPE_CHECKING
66

7-
from ...const import API_PATH
7+
from praw.const import API_PATH
8+
89
from .mixins import BaseListingMixin, RisingListingMixin
910

1011
if TYPE_CHECKING: # pragma: no cover
@@ -14,7 +15,7 @@
1415
class DomainListing(BaseListingMixin, RisingListingMixin):
1516
"""Provide a set of functions to interact with domain listings."""
1617

17-
def __init__(self, reddit: praw.Reddit, domain: str):
18+
def __init__(self, reddit: praw.Reddit, domain: str) -> None:
1819
"""Initialize a :class:`.DomainListing` instance.
1920
2021
:param reddit: An instance of :class:`.Reddit`.

0 commit comments

Comments
 (0)