Skip to content

Commit

Permalink
fix: Fix importing Middleware type alias (#185)
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 committed Nov 23, 2023
1 parent bc4bb6c commit 2f772e7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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,14 @@
)

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

try:
# (<3.9.0) Try to import Middleware from aiohttp.web_middlewares
Middleware = importlib.import_module('aiohttp.web_middlewares')._Middleware
except AttributeError:
# (>=3.9.0) 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 2f772e7

Please sign in to comment.