Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
5 changes: 2 additions & 3 deletions asyncpraw/objector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 8 additions & 11 deletions asyncpraw/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@

UPDATE_CHECKER_MISSING = False
except ImportError: # pragma: no cover
update_check = None
UPDATE_CHECKER_MISSING = True

if TYPE_CHECKING:
from collections.abc import AsyncGenerator, Iterable

import asyncprawcore

import asyncpraw
import asyncpraw.models

Comment = models.Comment
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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 {}

Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Loading