diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 9116594a..b140c57e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -81,6 +81,17 @@ body: type: input validations: required: true + - id: sync-praw + attributes: + description: Does this issue also occur in `praw`? + label: Does this issue occur in `praw`? + multiple: false + options: + - "Yes" + - "No" + type: dropdown + validations: + required: true - id: anything-else attributes: description: Anything that will give us more context about the issue you are encountering! diff --git a/CHANGES.rst b/CHANGES.rst index dc5909ff..a9a07b46 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -87,6 +87,7 @@ Unreleased - Remove key ``reset_timestamp`` from :meth:`.limits`. - Remove ``SubredditMessage.mute`` and ``SubredditMessage.unmute`` methods. - Remove ``InboxableMixin.unblock_subreddit`` method. +- Remove ``Reddit.close`` method. Use ``async with Reddit(...)`` instead. 7.8.1 (2024/12/21) ------------------ diff --git a/asyncpraw/objector.py b/asyncpraw/objector.py index bb5a4130..4369eefc 100644 --- a/asyncpraw/objector.py +++ b/asyncpraw/objector.py @@ -34,9 +34,8 @@ def parse_error(cls, data: list[Any] | dict[str, dict[str, str]]) -> RedditAPIEx """ if isinstance(data, list): - # Fetching a Submission returns a list (of two items). - # Although it's handled manually in `Submission._fetch()`, - # assume it's a possibility here. + # Fetching a Submission returns a list (of two items). Although it's handled + # manually in `Submission._fetch()`, assume it's a possibility here. return None errors = data.get("json", {}).get("errors") diff --git a/asyncpraw/reddit.py b/asyncpraw/reddit.py index e6eea84a..4aa26bf7 100644 --- a/asyncpraw/reddit.py +++ b/asyncpraw/reddit.py @@ -36,6 +36,7 @@ UPDATE_CHECKER_MISSING = False except ImportError: # pragma: no cover + update_check = None UPDATE_CHECKER_MISSING = True if TYPE_CHECKING: @@ -43,7 +44,6 @@ import asyncprawcore - import asyncpraw import asyncpraw.models Comment = models.Comment @@ -110,7 +110,8 @@ async def __aenter__(self): # noqa: ANN204 async def __aexit__(self, *_: object) -> None: """Handle the context manager close.""" - await self.close() + if self._core is not None: + await self._core.close() def __deepcopy__(self, memodict: dict[str, Any] | None = None) -> Reddit: """Shallow copy on deepcopy. @@ -209,7 +210,9 @@ async def request(self, *args, **kwargs): await reddit.close() """ - self._core = self._authorized_core = self._read_only_core = None + self._core: asyncprawcore.Session | None = None + self._authorized_core: asyncprawcore.Session | None = None + self._read_only_core: asyncprawcore.Session | None = None self._objector: Objector self._unique_counter = 0 @@ -243,7 +246,7 @@ async def request(self, *args, **kwargs): raise MissingRequiredAttributeException(msg) self._check_for_update() self._prepare_objector() - self.requestor = self._prepare_asyncprawcore(requestor_class=requestor_class, requestor_kwargs=requestor_kwargs) + self._prepare_asyncprawcore(requestor_class=requestor_class, requestor_kwargs=requestor_kwargs) self.auth = models.Auth(self, None) """An instance of :class:`.Auth`. @@ -500,7 +503,7 @@ def _prepare_asyncprawcore( *, requestor_class: type[Requestor] | None = None, requestor_kwargs: Any | None = None, - ) -> Requestor: + ) -> None: requestor_class = requestor_class or Requestor requestor_kwargs = requestor_kwargs or {} @@ -516,8 +519,6 @@ def _prepare_asyncprawcore( else: self._prepare_untrusted_asyncprawcore(requestor) - return requestor - def _prepare_common_authorizer(self, authenticator: asyncprawcore.auth.BaseAuthenticator) -> None: if self.config.refresh_token: authorizer = Authorizer(authenticator, refresh_token=self.config.refresh_token) @@ -608,10 +609,6 @@ async def _resolve_share_url(self, url: str) -> str: return e.response.headers.get("location") return url - async def close(self) -> None: - """Close the requestor.""" - await self.requestor.close() - async def comment( self, id: str | None = None, diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 033cca1c..acc02419 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -1,11 +1,10 @@ import os import sys from pathlib import Path +from unittest import mock import pytest -from unittest import mock - from asyncpraw.config import Config from asyncpraw.exceptions import ClientException