Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning displayed by default #7677

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
"""Warning when not using AppKey in Application."""


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