Skip to content

Commit

Permalink
Fix importing Middleware type alias
Browse files Browse the repository at this point in the history
_Middleware was removed upstream in [#5898][0]. We can now use
`Middleware` type alias from the typedefs starting from aiohttp 3.9.0

[0]: aio-libs/aiohttp#5898
  • Loading branch information
mprasil authored and mprasil committed Nov 21, 2023
1 parent bc4bb6c commit 48358b9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/aiohttp_middlewares/annotations.py
Expand Up @@ -7,6 +7,8 @@
"""

import importlib

from typing import (
Any,
Awaitable,
Expand All @@ -19,9 +21,15 @@
)

from aiohttp import web
from aiohttp.web_middlewares import _Middleware as Middleware
from yarl import URL

try:
# Try to import Middleware from aiohttp.web_middlewares
Middleware = importlib.import_module('aiohttp.web_middlewares')._Middleware
except ImportError:
# If that fails, import Middleware from aiohttp.typedefs
Middleware = importlib.import_module('aiohttp.typedefs').Middleware


# Make flake8 happy
(Middleware,)
Expand Down

0 comments on commit 48358b9

Please sign in to comment.