From 6f03ff90d052b374b4c7a4aeb5bb4b877b4aa4cb Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 8 Oct 2023 15:53:19 +0100 Subject: [PATCH 1/4] Fix warning displayed by default. --- aiohttp/web.py | 6 ++++++ aiohttp/web_app.py | 2 ++ aiohttp/web_exceptions.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/aiohttp/web.py b/aiohttp/web.py index f87d57988be..a219eb1afdc 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -3,6 +3,7 @@ import os import socket import sys +import warnings from argparse import ArgumentParser from collections.abc import Iterable from importlib import import_module @@ -25,6 +26,7 @@ from .typedefs import PathLike from .web_app import Application, CleanupError from .web_exceptions import ( + NotAppKeyWarning, HTTPAccepted, HTTPBadGateway, HTTPBadRequest, @@ -139,6 +141,7 @@ "Application", "CleanupError", # web_exceptions + "NotAppKeyWarning", "HTTPAccepted", "HTTPBadGateway", "HTTPBadRequest", @@ -268,6 +271,9 @@ except ImportError: # pragma: no cover SSLContext = Any # type: ignore[misc,assignment] +# Only display warning when using -Wdefault, -We, -X dev or similar). +warnings.filterwarnings("ignore", category=NotAppKeyWarning, append=True) + HostSequence = TypingIterable[str] diff --git a/aiohttp/web_app.py b/aiohttp/web_app.py index 5be96084693..614c81fb9c4 100644 --- a/aiohttp/web_app.py +++ b/aiohttp/web_app.py @@ -31,6 +31,7 @@ from .helpers import AppKey from .log import web_logger from .typedefs import Middleware +from .web_exceptions import NotAppKeyWarning from .web_middlewares import _fix_request_current_app from .web_request import Request from .web_response import StreamResponse @@ -173,6 +174,7 @@ def __setitem__(self, key: Union[str, AppKey[_T]], value: Any) -> None: "It is recommended to use web.AppKey instances for keys.\n" + "https://docs.aiohttp.org/en/stable/web_advanced.html" + "#application-s-config", + category=NotAppKeyWarning, stacklevel=2, ) self._state[key] = value diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py index 332ca9fa565..70355aac8b1 100644 --- a/aiohttp/web_exceptions.py +++ b/aiohttp/web_exceptions.py @@ -71,6 +71,10 @@ ) +class NotAppKeyWarning(UserWarning): + """Warning when not using AppKey in Application.""" + + ############################################################ # HTTP Exceptions ############################################################ From 7009fedf518894ff231c7b2e70be8c200241a0c3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:54:41 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- aiohttp/web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/web.py b/aiohttp/web.py index a219eb1afdc..261ab8bd266 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -26,7 +26,6 @@ from .typedefs import PathLike from .web_app import Application, CleanupError from .web_exceptions import ( - NotAppKeyWarning, HTTPAccepted, HTTPBadGateway, HTTPBadRequest, @@ -85,6 +84,7 @@ HTTPUseProxy, HTTPVariantAlsoNegotiates, HTTPVersionNotSupported, + NotAppKeyWarning, ) from .web_fileresponse import FileResponse from .web_log import AccessLogger From 1af4103e6ffdf5fec91f740cea9be73d881da7fa Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 8 Oct 2023 15:56:00 +0100 Subject: [PATCH 3/4] Create 7677.bugfix --- CHANGES/7677.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/7677.bugfix diff --git a/CHANGES/7677.bugfix b/CHANGES/7677.bugfix new file mode 100644 index 00000000000..ca20004121a --- /dev/null +++ b/CHANGES/7677.bugfix @@ -0,0 +1 @@ +Changed ``AppKey`` warning to ``web.NotAppKeyWarning`` and stop it being displayed by default. -- by :user:`Dreamsorcerer` From 5d2e063cb76cf75950c0494fc8a3403b120b2bcd Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 8 Oct 2023 16:09:57 +0100 Subject: [PATCH 4/4] Update web.py --- aiohttp/web.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiohttp/web.py b/aiohttp/web.py index 261ab8bd266..242f7a96ced 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -271,7 +271,7 @@ except ImportError: # pragma: no cover SSLContext = Any # type: ignore[misc,assignment] -# Only display warning when using -Wdefault, -We, -X dev or similar). +# Only display warning when using -Wdefault, -We, -X dev or similar. warnings.filterwarnings("ignore", category=NotAppKeyWarning, append=True) HostSequence = TypingIterable[str]