Skip to content

Commit 466f1eb

Browse files
authored
Increase stacklevel for UserWarning about AppKey usage (#7484)
1 parent c0c7508 commit 466f1eb

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ Lukasz Marcin Dobrzanski
215215
Makc Belousow
216216
Manuel Miranda
217217
Marat Sharafutdinov
218+
Marc Mueller
218219
Marco Paolini
219220
Mariano Anaya
220221
Mariusz Masztalerczuk

aiohttp/web_app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ def __setitem__(self, key: Union[str, AppKey[_T]], value: Any) -> None:
173173
warnings.warn(
174174
"It is recommended to use web.AppKey instances for keys.\n"
175175
+ "https://docs.aiohttp.org/en/stable/web_advanced.html"
176-
+ "#application-s-config"
176+
+ "#application-s-config",
177+
stacklevel=2,
177178
)
178179
self._state[key] = value
179180

tests/test_web_app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ def test_appkey_repr_annotated() -> None:
144144

145145
def test_app_str_keys() -> None:
146146
app = web.Application()
147-
with pytest.warns(UserWarning, match=r"web_advanced\.html#application-s-config"):
147+
with pytest.warns(
148+
UserWarning, match=r"web_advanced\.html#application-s-config"
149+
) as checker:
148150
app["key"] = "value"
151+
# Check that the error is emitted at the call site (stacklevel=2)
152+
assert checker[0].filename == __file__
149153
assert app["key"] == "value"
150154

151155

0 commit comments

Comments
 (0)