Added depreciated warning in filter warning#3198
Conversation
ichard26
left a comment
There was a problem hiding this comment.
There is no mitigation here, it's simply ignoring the issue. We might want to also try except this decorator though similar to #2974 so when aiohttp does remove this decorator, nothing breaks :)
Thoughts @graingert ?
Yeah you need to mitigate this with a try/catch ImportError |
| xfail_strict = true | ||
| filterwarnings = [ | ||
| "error", | ||
| # this ignore can be removed when @middleware is removed from the codebase. |
There was a problem hiding this comment.
My intention was that you'd apply the mitigation rather than change the comment ;)
There was a problem hiding this comment.
@graingert I am not getting it. You want me to raise Import Error exception on catching Depreciation Warning?
There was a problem hiding this comment.
I want you to catch the ImportError not raise it like this
|
Sounds like we should not do this and instead actually fix the warning. |
Signed-off-by: Shivam Durgbuns <shivamdurgbuns@gmail.com>
Has the fix been made? Or should I add an exception for this? |
Signed-off-by: Shivam Durgbuns <shivamdurgbuns@gmail.com>
c4375ae to
32c0f6f
Compare
|
Sorry @shivamdurgbuns, but looks like we haven't been clear enough on what needs to be done. We want to mitigate the deprecation of diff --git a/pyproject.toml b/pyproject.toml
index 813e86b..849891f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -105,6 +105,9 @@ filterwarnings = [
# this is mitigated by a try/catch in https://github.com/psf/black/pull/2974/
# this ignore can be removed when support for aiohttp 3.7 is dropped.
'''ignore:Decorator `@unittest_run_loop` is no longer needed in aiohttp 3\.8\+:DeprecationWarning''',
+ # this is mitigated by a try/catch in https://github.com/psf/black/pull/3198/
+ # this ignore can be removed when support for aiohttp 3.x is dropped.
+ '''ignore:Middleware decorator is deprecated since 4\.0 and its behaviour is default, you can simply remove this decorator:DeprecationWarning''',
# this is mitigated by https://github.com/python/cpython/issues/79071 in python 3.8+
# this ignore can be removed when support for 3.7 is dropped.
'''ignore:Bare functions are deprecated, use async ones:DeprecationWarning''',
diff --git a/src/blackd/middlewares.py b/src/blackd/middlewares.py
index 7abde52..2be42b0 100644
--- a/src/blackd/middlewares.py
+++ b/src/blackd/middlewares.py
@@ -1,9 +1,19 @@
-from typing import Awaitable, Callable, Iterable
+from typing import TYPE_CHECKING, Awaitable, Callable, Iterable, TypeVar
-from aiohttp.web_middlewares import middleware
from aiohttp.web_request import Request
from aiohttp.web_response import 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, just define a no-op decorator for compatibility.
+ middleware = lambda x: x
+
+if TYPE_CHECKING:
+ F = TypeVar("F", bound=Callable[..., Any])
+ middleware: Callable[[F], F] = lambda x: x
+
Handler = Callable[[Request], Awaitable[StreamResponse]]Here are roughly the changes we'd like, although this is mostly untested. |
Signed-off-by: Shivam Durgbuns shivamdurgbuns@gmail.com
fixes: #3176
Description
Checklist - did you ...