Skip to content

Commit e1fc600

Browse files
committed
minor
1 parent e7879f9 commit e1fc600

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/service-library/src/servicelib/aiohttp/web_exceptions_extension.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
import inspect
6-
from typing import Any
6+
from typing import Any, TypeVar
77

88
from aiohttp import web_exceptions
99
from aiohttp.web_exceptions import (
@@ -40,15 +40,18 @@ class HTTPLoopDetectedError(HTTPServerError):
4040
status_code = status.HTTP_508_LOOP_DETECTED
4141

4242

43+
E = TypeVar("E", bound="HTTPException")
44+
45+
4346
def get_all_aiohttp_http_exceptions(
44-
exception_cls: type[HTTPException] = HTTPException,
45-
) -> dict[int, type[HTTPException]]:
47+
base_http_exception_cls: type[E],
48+
) -> dict[int, type[E]]:
4649
# Inverse map from code to HTTPException classes
4750

4851
def _pred(obj) -> bool:
4952
return (
5053
inspect.isclass(obj)
51-
and issubclass(obj, exception_cls)
54+
and issubclass(obj, base_http_exception_cls)
5255
and getattr(obj, "status_code", 0) > 0
5356
)
5457

@@ -62,8 +65,7 @@ def _pred(obj) -> bool:
6265
HTTPLockedError,
6366
HTTPLoopDetectedError,
6467
):
65-
66-
status_to_http_exception_map[cls.status_code] = cls # type:ignore
68+
status_to_http_exception_map[cls.status_code] = cls
6769

6870
return status_to_http_exception_map
6971

packages/service-library/tests/aiohttp/test_status_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from http import HTTPStatus
22

33
import pytest
4+
from fastapi import HTTPException
45
from servicelib.aiohttp import status
56
from servicelib.aiohttp.web_exceptions_extension import (
67
STATUS_CODES_WITHOUT_AIOHTTP_EXCEPTION_CLASS,
@@ -68,7 +69,9 @@ def test_predicates_with_status():
6869
]
6970

7071

71-
AIOHTTP_EXCEPTION_CLASSES_MAP = get_all_aiohttp_http_exceptions()
72+
AIOHTTP_EXCEPTION_CLASSES_MAP: dict[
73+
int, type[HTTPException]
74+
] = get_all_aiohttp_http_exceptions(HTTPException)
7275

7376

7477
@pytest.mark.parametrize("status_code", get_http_status_codes(status))

0 commit comments

Comments
 (0)