Skip to content

Commit

Permalink
Fix type error in blackd
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Aug 23, 2024
1 parent 7fa1faf commit 77d6d94
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/blackd/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
from aiohttp.web_request import Request
from aiohttp.web_response import StreamResponse

Handler = Callable[[Request], Awaitable[StreamResponse]]

if TYPE_CHECKING:
from aiohttp.typedefs import Middleware

F = TypeVar("F", bound=Callable[..., Any])
middleware: Callable[[F], F]
else:
try:
from aiohttp.typedefs import Middleware
except ImportError:
Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]

try:
from aiohttp.web_middlewares import middleware
except ImportError:
# @middleware is deprecated and its behaviour is the default since aiohttp 4.0
# so if it doesn't exist anymore, define a no-op for forward compatibility.
middleware = lambda x: x # noqa: E731

Handler = Callable[[Request], Awaitable[StreamResponse]]
Middleware = Callable[[Request, Handler], Awaitable[StreamResponse]]


def cors(allow_headers: Iterable[str]) -> Middleware:
@middleware
Expand Down

0 comments on commit 77d6d94

Please sign in to comment.