Fix type error in blackd (#4442)

This commit is contained in:
Shantanu 2024-08-22 18:17:32 -07:00 committed by GitHub
parent c20423249e
commit 699b45aef7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,10 +3,20 @@
from aiohttp.web_request import Request from aiohttp.web_request import Request
from aiohttp.web_response import StreamResponse from aiohttp.web_response import StreamResponse
Handler = Callable[[Request], Awaitable[StreamResponse]]
if TYPE_CHECKING: if TYPE_CHECKING:
from aiohttp.typedefs import Middleware
F = TypeVar("F", bound=Callable[..., Any]) F = TypeVar("F", bound=Callable[..., Any])
middleware: Callable[[F], F] middleware: Callable[[F], F]
else: else:
try:
# Available in aiohttp 3.9 and newer
from aiohttp.typedefs import Middleware
except ImportError:
Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]
try: try:
from aiohttp.web_middlewares import middleware from aiohttp.web_middlewares import middleware
except ImportError: except ImportError:
@ -14,9 +24,6 @@
# so if it doesn't exist anymore, define a no-op for forward compatibility. # so if it doesn't exist anymore, define a no-op for forward compatibility.
middleware = lambda x: x # noqa: E731 middleware = lambda x: x # noqa: E731
Handler = Callable[[Request], Awaitable[StreamResponse]]
Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]
def cors(allow_headers: Iterable[str]) -> Middleware: def cors(allow_headers: Iterable[str]) -> Middleware:
@middleware @middleware