Skip to content

Commit

Permalink
Merge branch 'main' into fix-pep-646-support
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Aug 23, 2024
2 parents 755905c + 699b45a commit 0e05bbf
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/blackd/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
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:
# Available in aiohttp 3.9 and newer
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 0e05bbf

Please sign in to comment.