From ce87607bcc39b6d6c69c8e8a3f7bb582dfd40993 Mon Sep 17 00:00:00 2001 From: LilSpazJoekp <15524072+LilSpazJoekp@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:36:12 -0600 Subject: [PATCH] Fix coverage issues (cherry picked from commit praw-dev/prawcore@83aa52c420479bd97974bfd8bbc4c51a434c86c4) --- .coveragerc | 5 +++++ asyncprawcore/auth.py | 2 +- asyncprawcore/exceptions.py | 2 +- asyncprawcore/rate_limit.py | 2 +- asyncprawcore/requestor.py | 2 +- asyncprawcore/sessions.py | 2 +- asyncprawcore/util.py | 7 ++++++- 7 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..b1dd481 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[report] +exclude_lines = + @abstract + if TYPE_CHECKING: + pragma: no cover diff --git a/asyncprawcore/auth.py b/asyncprawcore/auth.py index 6b85f01..6a1c5f4 100644 --- a/asyncprawcore/auth.py +++ b/asyncprawcore/auth.py @@ -22,7 +22,7 @@ from .codes import codes from .exceptions import InvalidInvocation, OAuthException, ResponseException -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from asyncprawcore.requestor import Requestor diff --git a/asyncprawcore/exceptions.py b/asyncprawcore/exceptions.py index e829a23..4623c83 100644 --- a/asyncprawcore/exceptions.py +++ b/asyncprawcore/exceptions.py @@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union from urllib.parse import urlparse -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from aiohttp import ClientResponse diff --git a/asyncprawcore/rate_limit.py b/asyncprawcore/rate_limit.py index 366a8ce..59839e8 100644 --- a/asyncprawcore/rate_limit.py +++ b/asyncprawcore/rate_limit.py @@ -4,7 +4,7 @@ import time from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Mapping, Optional -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from aiohttp import ClientResponse log = logging.getLogger(__package__) diff --git a/asyncprawcore/requestor.py b/asyncprawcore/requestor.py index af36d02..8d7bca9 100644 --- a/asyncprawcore/requestor.py +++ b/asyncprawcore/requestor.py @@ -7,7 +7,7 @@ from .const import TIMEOUT, __version__ from .exceptions import InvalidInvocation, RequestException -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from asyncio import AbstractEventLoop from .sessions import Session diff --git a/asyncprawcore/sessions.py b/asyncprawcore/sessions.py index 24e6c3a..312a470 100644 --- a/asyncprawcore/sessions.py +++ b/asyncprawcore/sessions.py @@ -30,7 +30,7 @@ from .rate_limit import RateLimiter from .util import authorization_error_class -if TYPE_CHECKING: # pragma: no cover +if TYPE_CHECKING: from io import BufferedReader from aiofiles.threadpool.binary import AsyncBufferedReader diff --git a/asyncprawcore/util.py b/asyncprawcore/util.py index de5e2c6..02ae7ba 100644 --- a/asyncprawcore/util.py +++ b/asyncprawcore/util.py @@ -1,6 +1,11 @@ """Provide utility for the asyncprawcore package.""" +from typing import TYPE_CHECKING, Union + from .exceptions import Forbidden, InsufficientScope, InvalidToken +if TYPE_CHECKING: + from aiohttp import ClientResponse + _auth_error_mapping = { 403: Forbidden, "insufficient_scope": InsufficientScope, @@ -8,7 +13,7 @@ } -def authorization_error_class(response): +def authorization_error_class(response: "ClientResponse") -> Union[InvalidToken, Forbidden, InsufficientScope]: """Return an exception instance that maps to the OAuth Error. :param response: The HTTP response containing a www-authenticate error.