Skip to content

Commit

Permalink
Fix warning displayed by default (aio-libs#7677)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Dreamsorcerer and pre-commit-ci[bot] authored Oct 26, 2023
1 parent 0dc39e4 commit 32a1bae
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/7677.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed ``AppKey`` warning to ``web.NotAppKeyWarning`` and stop it being displayed by default. -- by :user:`Dreamsorcerer`
6 changes: 6 additions & 0 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,7 @@
HTTPUseProxy,
HTTPVariantAlsoNegotiates,
HTTPVersionNotSupported,
NotAppKeyWarning,
)
from .web_fileresponse import FileResponse
from .web_log import AccessLogger
Expand Down Expand Up @@ -139,6 +141,7 @@
"Application",
"CleanupError",
# web_exceptions
"NotAppKeyWarning",
"HTTPAccepted",
"HTTPBadGateway",
"HTTPBadRequest",
Expand Down Expand Up @@ -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]


Expand Down
2 changes: 2 additions & 0 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions aiohttp/web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
)


class NotAppKeyWarning(UserWarning):
"""Warning when not using AppKey in Application."""


############################################################
# HTTP Exceptions
############################################################
Expand Down

0 comments on commit 32a1bae

Please sign in to comment.