diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4ea00e9..27f2246 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,5 +7,4 @@ updates: - package-ecosystem: uv directory: / schedule: - interval: cron - cronjob: "46 17 * * *" + interval: weekly diff --git a/CHANGES.rst b/CHANGES.rst index 57549c3..98070f6 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,10 @@ asyncprawcore follows `semantic versioning `_. Unreleased ---------- +**Changed** + +- Improved exception message when ``asyncio.TimeoutError`` is raised. + 3.0.2 (2025/08/06) ------------------ diff --git a/asyncprawcore/auth.py b/asyncprawcore/auth.py index 4fe6680..d6e8153 100644 --- a/asyncprawcore/auth.py +++ b/asyncprawcore/auth.py @@ -124,8 +124,8 @@ async def revoke_token(self, token: str, token_type: str | None = None) -> None: if token_type is not None: data["token_type_hint"] = token_type url = self._requestor.reddit_url + const.REVOKE_TOKEN_PATH - async with self._post(url=url, **data) as _: - pass # The response is not used. + async with self._post(url=url, **data): + pass class BaseAuthorizer: diff --git a/asyncprawcore/exceptions.py b/asyncprawcore/exceptions.py index 3984e4b..f19ad9f 100644 --- a/asyncprawcore/exceptions.py +++ b/asyncprawcore/exceptions.py @@ -2,6 +2,7 @@ from __future__ import annotations +import asyncio from typing import TYPE_CHECKING, Any from urllib.parse import urlparse @@ -56,7 +57,9 @@ def __init__( self.original_exception = original_exception self.request_args = request_args self.request_kwargs = request_kwargs - super().__init__(f"error with request {original_exception}") + super().__init__( + f"error with request {'TimeoutError' if isinstance(original_exception, asyncio.TimeoutError) else original_exception}" + ) class ResponseException(AsyncPrawcoreException): diff --git a/pyproject.toml b/pyproject.toml index 15fcac2..9860555 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -build-backend = "flit_core.buildapi" -requires = ["flit_core >=3.4,<4"] +build-backend = "hatchling.build" +requires = ["hatchling"] [dependency-groups] dev = [ @@ -61,6 +61,9 @@ requires-python = ">=3.9" "Issue Tracker" = "https://github.com/praw-dev/asyncprawcore/issues" "Source Code" = "https://github.com/praw-dev/asyncprawcore" +[tool.hatch.version] +path = "asyncprawcore/__init__.py" + [tool.pytest.ini_options] asyncio_mode = "auto" filterwarnings = "ignore::DeprecationWarning" @@ -68,8 +71,8 @@ testpaths = "tests" [tool.ruff] include = [ - "examples/*.py", "asyncprawcore/*.py", + "examples/*.py", "tests/*.py" ] line-length = 120 diff --git a/tests/unit/test_requestor.py b/tests/unit/test_requestor.py index 62f36a1..40ab7a3 100644 --- a/tests/unit/test_requestor.py +++ b/tests/unit/test_requestor.py @@ -68,3 +68,18 @@ async def test_request__wrap_request_exceptions(self, mock_session): assert exception is exception_info.value.original_exception assert exception_info.value.request_args == ("get", "http://a.b") assert exception_info.value.request_kwargs == {"data": "bar"} + + @patch("aiohttp.ClientSession") + async def test_request__wrap_request_exceptions__timeout(self, mock_session): + exception = asyncio.TimeoutError() + session_instance = mock_session.return_value + session_instance.request.side_effect = exception + requestor = asyncprawcore.Requestor("asyncprawcore:test (by u/Lil_SpazJoekp)") + with pytest.raises(asyncprawcore.RequestException) as exception_info: + async with requestor.request("get", "http://a.b", data="bar") as _: + pass # pragma: no cover + assert isinstance(exception_info.value, RequestException) + assert exception is exception_info.value.original_exception + assert str(exception_info.value) == "error with request TimeoutError" + assert exception_info.value.request_args == ("get", "http://a.b") + assert exception_info.value.request_kwargs == {"data": "bar"}