Skip to content

Commit debe81d

Browse files
committed
Manually resolve additional ruff issues
1 parent 37984c5 commit debe81d

30 files changed

Lines changed: 136 additions & 110 deletions

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/config.py

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

1314
from .exceptions import ClientException
@@ -29,13 +30,13 @@ 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"}
@@ -123,11 +124,11 @@ def _fetch_or_not_set(self, key: str) -> Any | _NotSet:
123124

124125
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/exceptions.py

Lines changed: 1 addition & 1 deletion
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

praw/models/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def info(self, ids: list[str]) -> Generator[praw.models.LiveThread, None, None]:
214214
msg = "ids must be a list"
215215
raise TypeError(msg)
216216

217-
def generator():
217+
def generator() -> Generator[praw.models.LiveThread, None, None]:
218218
for position in range(0, len(ids), 100):
219219
ids_chunk = ids[position : position + 100]
220220
url = API_PATH["live_info"].format(ids=",".join(ids_chunk))

praw/models/inbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def unread(
296296
self,
297297
*,
298298
mark_read: bool = False,
299-
**generator_kwargs: str | int | dict[str, str],
299+
**generator_kwargs: str | int | dict[str, str] | None,
300300
) -> Iterator[praw.models.Comment | praw.models.Message]:
301301
"""Return a :class:`.ListingGenerator` for unread comments and messages.
302302

praw/models/list/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, reddit: praw.Reddit, _data: dict[str, Any]) -> None:
3939

4040
child_list = getattr(self, self.CHILD_ATTRIBUTE)
4141
for index, item in enumerate(child_list):
42-
child_list[index] = reddit._objector.objectify(item)
42+
child_list[index] = reddit._objector.objectify(data=item)
4343

4444
def __iter__(self) -> Iterator[Any]:
4545
"""Return an iterator to the list."""

praw/models/listing/generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __next__(self) -> Any:
7171
self.yielded += 1
7272
return self._listing[self._list_index - 1]
7373

74-
def _extract_sublist(self, listing: dict[str, Any] | list[Any]):
74+
def _extract_sublist(self, listing: dict[str, Any] | list[Any] | Any) -> Any:
7575
if isinstance(listing, list):
7676
return listing[1] # for submission duplicates
7777
if isinstance(listing, dict):

praw/models/listing/listing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __len__(self) -> int:
2424
def __setattr__(self, attribute: str, value: Any) -> None:
2525
"""Objectify the ``CHILD_ATTRIBUTE`` attribute."""
2626
if attribute == self.CHILD_ATTRIBUTE:
27-
value = self._reddit._objector.objectify(value)
27+
value = self._reddit._objector.objectify(data=value)
2828
super().__setattr__(attribute, value)
2929

3030

praw/models/listing/mixins/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class BaseListingMixin(PRAWBase):
1616
"""Adds minimum set of methods that apply to all listing objects."""
1717

18-
VALID_TIME_FILTERS = {"all", "day", "hour", "month", "week", "year"}
18+
VALID_TIME_FILTERS = frozenset({"all", "day", "hour", "month", "week", "year"})
1919

2020
@staticmethod
2121
def _validate_time_filter(time_filter: str) -> None:

praw/models/mod_notes.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _all_generator(
4040
redditor: Redditor | str,
4141
subreddit: Subreddit | str,
4242
**generator_kwargs: Any,
43-
):
43+
) -> ListingGenerator:
4444
PRAWBase._safely_add_arguments(
4545
arguments=generator_kwargs,
4646
key="params",
@@ -65,7 +65,7 @@ def _bulk_generator(
6565
}
6666
response = self._reddit.get(API_PATH["mod_notes_bulk"], params=params)
6767
for note_dict in response["mod_notes"]:
68-
yield self._reddit._objector.objectify(note_dict)
68+
yield self._reddit._objector.objectify(data=note_dict)
6969

7070
def _ensure_attribute(self, error_message: str, **attributes: Any) -> Any:
7171
attribute, value_ = attributes.popitem()
@@ -76,6 +76,7 @@ def _ensure_attribute(self, error_message: str, **attributes: Any) -> Any:
7676

7777
def _notes(
7878
self,
79+
*,
7980
all_notes: bool,
8081
redditors: list[Redditor | str],
8182
subreddits: list[Subreddit | str],
@@ -261,7 +262,7 @@ def delete(
261262
msg = "Either 'note_id' or 'delete_all' must be provided."
262263
raise TypeError(msg)
263264
if delete_all:
264-
for note in self._notes(True, [redditor], [subreddit]):
265+
for note in self._notes(all_notes=True, redditors=[redditor], subreddits=[subreddit]):
265266
note.delete()
266267
else:
267268
params = {
@@ -361,9 +362,9 @@ def subreddits(
361362
if all_notes is None:
362363
all_notes = len(subreddits) == 1
363364
return self._notes(
364-
all_notes,
365-
[self.redditor] * len(subreddits),
366-
list(subreddits),
365+
all_notes=all_notes,
366+
redditors=[self.redditor] * len(subreddits),
367+
subreddits=list(subreddits),
367368
**generator_kwargs,
368369
)
369370

@@ -457,9 +458,9 @@ def redditors(
457458
if all_notes is None:
458459
all_notes = len(redditors) == 1
459460
return self._notes(
460-
all_notes,
461-
list(redditors),
462-
[self.subreddit] * len(redditors),
461+
all_notes=all_notes,
462+
redditors=list(redditors),
463+
subreddits=[self.subreddit] * len(redditors),
463464
**generator_kwargs,
464465
)
465466

@@ -627,8 +628,10 @@ def __call__(
627628
merged_subreddits.append(subreddit)
628629
else:
629630
msg = f"Cannot get subreddit and author fields from type {type(item)}"
630-
raise ValueError(msg)
631-
return self._notes(all_notes, merged_redditors, merged_subreddits, **generator_kwargs)
631+
raise TypeError(msg)
632+
return self._notes(
633+
all_notes=all_notes, redditors=merged_redditors, subreddits=merged_subreddits, **generator_kwargs
634+
)
632635

633636
def things(
634637
self,
@@ -678,4 +681,4 @@ def things(
678681
redditors.append(thing.author)
679682
if all_notes is None:
680683
all_notes = len(things) == 1
681-
return self._notes(all_notes, redditors, subreddits, **generator_kwargs)
684+
return self._notes(all_notes=all_notes, redditors=redditors, subreddits=subreddits, **generator_kwargs)

0 commit comments

Comments
 (0)