Skip to content

Commit 1a7902e

Browse files
committed
Finishing touches for cleanup
1 parent a99cfe2 commit 1a7902e

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ body:
8181
type: input
8282
validations:
8383
required: true
84+
- id: sync-praw
85+
attributes:
86+
description: Does this issue also occur in `praw`?
87+
label: Does this issue occur in `praw`?
88+
multiple: false
89+
options:
90+
- "Yes"
91+
- "No"
92+
type: dropdown
93+
validations:
94+
required: true
8495
- id: anything-else
8596
attributes:
8697
description: Anything that will give us more context about the issue you are encountering!

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Unreleased
8787
- Remove key ``reset_timestamp`` from :meth:`.limits`.
8888
- Remove ``SubredditMessage.mute`` and ``SubredditMessage.unmute`` methods.
8989
- Remove ``InboxableMixin.unblock_subreddit`` method.
90+
- Remove ``Reddit.close`` method. Use ``async with Reddit(...)`` instead.
9091

9192
7.8.1 (2024/12/21)
9293
------------------

asyncpraw/objector.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def parse_error(cls, data: list[Any] | dict[str, dict[str, str]]) -> RedditAPIEx
3434
3535
"""
3636
if isinstance(data, list):
37-
# Fetching a Submission returns a list (of two items).
38-
# Although it's handled manually in `Submission._fetch()`,
39-
# assume it's a possibility here.
37+
# Fetching a Submission returns a list (of two items). Although it's handled
38+
# manually in `Submission._fetch()`, assume it's a possibility here.
4039
return None
4140

4241
errors = data.get("json", {}).get("errors")

asyncpraw/reddit.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636

3737
UPDATE_CHECKER_MISSING = False
3838
except ImportError: # pragma: no cover
39+
update_check = None
3940
UPDATE_CHECKER_MISSING = True
4041

4142
if TYPE_CHECKING:
4243
from collections.abc import AsyncGenerator, Iterable
4344

4445
import asyncprawcore
4546

46-
import asyncpraw
4747
import asyncpraw.models
4848

4949
Comment = models.Comment
@@ -110,7 +110,8 @@ async def __aenter__(self): # noqa: ANN204
110110

111111
async def __aexit__(self, *_: object) -> None:
112112
"""Handle the context manager close."""
113-
await self.close()
113+
if self._core is not None:
114+
await self._core.close()
114115

115116
def __deepcopy__(self, memodict: dict[str, Any] | None = None) -> Reddit:
116117
"""Shallow copy on deepcopy.
@@ -209,7 +210,9 @@ async def request(self, *args, **kwargs):
209210
await reddit.close()
210211
211212
"""
212-
self._core = self._authorized_core = self._read_only_core = None
213+
self._core: asyncprawcore.Session | None = None
214+
self._authorized_core: asyncprawcore.Session | None = None
215+
self._read_only_core: asyncprawcore.Session | None = None
213216
self._objector: Objector
214217
self._unique_counter = 0
215218

@@ -243,7 +246,7 @@ async def request(self, *args, **kwargs):
243246
raise MissingRequiredAttributeException(msg)
244247
self._check_for_update()
245248
self._prepare_objector()
246-
self.requestor = self._prepare_asyncprawcore(requestor_class=requestor_class, requestor_kwargs=requestor_kwargs)
249+
self._prepare_asyncprawcore(requestor_class=requestor_class, requestor_kwargs=requestor_kwargs)
247250

248251
self.auth = models.Auth(self, None)
249252
"""An instance of :class:`.Auth`.
@@ -500,7 +503,7 @@ def _prepare_asyncprawcore(
500503
*,
501504
requestor_class: type[Requestor] | None = None,
502505
requestor_kwargs: Any | None = None,
503-
) -> Requestor:
506+
) -> None:
504507
requestor_class = requestor_class or Requestor
505508
requestor_kwargs = requestor_kwargs or {}
506509

@@ -516,8 +519,6 @@ def _prepare_asyncprawcore(
516519
else:
517520
self._prepare_untrusted_asyncprawcore(requestor)
518521

519-
return requestor
520-
521522
def _prepare_common_authorizer(self, authenticator: asyncprawcore.auth.BaseAuthenticator) -> None:
522523
if self.config.refresh_token:
523524
authorizer = Authorizer(authenticator, refresh_token=self.config.refresh_token)
@@ -608,10 +609,6 @@ async def _resolve_share_url(self, url: str) -> str:
608609
return e.response.headers.get("location")
609610
return url
610611

611-
async def close(self) -> None:
612-
"""Close the requestor."""
613-
await self.requestor.close()
614-
615612
async def comment(
616613
self,
617614
id: str | None = None,

tests/unit/test_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import os
22
import sys
33
from pathlib import Path
4+
from unittest import mock
45

56
import pytest
67

7-
from unittest import mock
8-
98
from asyncpraw.config import Config
109
from asyncpraw.exceptions import ClientException
1110

0 commit comments

Comments
 (0)