File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 33"""
44
55import inspect
6- from typing import Any
6+ from typing import Any , TypeVar
77
88from aiohttp import web_exceptions
99from 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+
4346def 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
Original file line number Diff line number Diff line change 11from http import HTTPStatus
22
33import pytest
4+ from fastapi import HTTPException
45from servicelib .aiohttp import status
56from 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 ))
You can’t perform that action at this time.
0 commit comments