Skip to content

Commit 45e51dc

Browse files
authored
Use StarletteDeprecationWarning instead of DeprecationWarning (#3119)
1 parent 5f8610c commit 45e51dc

9 files changed

Lines changed: 22 additions & 12 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ xfail_strict = true
112112
filterwarnings = [
113113
# Turn warnings that aren't filtered into exceptions
114114
"error",
115-
"ignore: run_until_first_complete is deprecated and will be removed in a future version.:DeprecationWarning",
116-
"ignore: starlette.middleware.wsgi is deprecated and will be removed in a future release.*:DeprecationWarning",
115+
"ignore: run_until_first_complete is deprecated and will be removed in a future version.:starlette.exceptions.StarletteDeprecationWarning",
116+
"ignore: starlette.middleware.wsgi is deprecated and will be removed in a future release.*:starlette.exceptions.StarletteDeprecationWarning",
117117
"ignore: Async generator 'starlette.requests.Request.stream' was garbage collected before it had been exhausted.*:ResourceWarning",
118118
"ignore: Use 'content=<...>' to upload raw bytes/text content.:DeprecationWarning",
119119
"ignore: Using `httpx` with `starlette.testclient` is deprecated.*:starlette.exceptions.StarletteDeprecationWarning",

starlette/concurrency.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
import anyio.to_thread
99

10+
from starlette.exceptions import StarletteDeprecationWarning
11+
1012
P = ParamSpec("P")
1113
T = TypeVar("T")
1214

1315

1416
async def run_until_first_complete(*args: tuple[Callable, dict]) -> None: # type: ignore[type-arg]
1517
warnings.warn(
1618
"run_until_first_complete is deprecated and will be removed in a future version.",
17-
DeprecationWarning,
19+
StarletteDeprecationWarning,
1820
)
1921

2022
async with anyio.create_task_group() as task_group:

starlette/middleware/wsgi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from anyio.abc import ObjectReceiveStream, ObjectSendStream
1212

1313
from starlette._utils import create_collapsing_task_group
14+
from starlette.exceptions import StarletteDeprecationWarning
1415
from starlette.types import Receive, Scope, Send
1516

1617
warnings.warn(
1718
"starlette.middleware.wsgi is deprecated and will be removed in a future release. "
1819
"Please refer to https://github.com/abersheeran/a2wsgi as a replacement.",
19-
DeprecationWarning,
20+
StarletteDeprecationWarning,
2021
stacklevel=2,
2122
)
2223

starlette/routing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from starlette.concurrency import run_in_threadpool
1919
from starlette.convertors import CONVERTOR_TYPES, Convertor
2020
from starlette.datastructures import URL, Headers, URLPath
21-
from starlette.exceptions import HTTPException
21+
from starlette.exceptions import HTTPException, StarletteDeprecationWarning
2222
from starlette.middleware import Middleware
2323
from starlette.requests import Request
2424
from starlette.responses import PlainTextResponse, RedirectResponse, Response
@@ -586,13 +586,13 @@ def __init__(
586586
warnings.warn(
587587
"async generator function lifespans are deprecated, "
588588
"use an @contextlib.asynccontextmanager function instead",
589-
DeprecationWarning,
589+
StarletteDeprecationWarning,
590590
)
591591
self.lifespan_context = asynccontextmanager(lifespan)
592592
elif inspect.isgeneratorfunction(lifespan):
593593
warnings.warn(
594594
"generator function lifespans are deprecated, use an @contextlib.asynccontextmanager function instead",
595-
DeprecationWarning,
595+
StarletteDeprecationWarning,
596596
)
597597
self.lifespan_context = _wrap_gen_lifespan_context(lifespan)
598598
else:

starlette/status.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import warnings
1212

13+
from starlette.exceptions import StarletteDeprecationWarning
14+
1315
__all__ = [
1416
"HTTP_100_CONTINUE",
1517
"HTTP_101_SWITCHING_PROTOCOLS",
@@ -197,7 +199,7 @@ def __getattr__(name: str) -> int:
197199
if deprecated:
198200
warnings.warn(
199201
f"'{name}' is deprecated. Use '{deprecation_changes[name]}' instead.",
200-
category=DeprecationWarning,
202+
category=StarletteDeprecationWarning,
201203
stacklevel=3,
202204
)
203205
return deprecated

starlette/testclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def request( # type: ignore[override]
447447
warnings.warn(
448448
"You should not use the 'timeout' argument with the TestClient. "
449449
"See https://github.com/Kludex/starlette/issues/1108 for more information.",
450-
DeprecationWarning,
450+
StarletteDeprecationWarning,
451451
stacklevel=2,
452452
)
453453
url = self._merge_url(url)

tests/test_applications.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ async def lifespan(app: ASGIApp) -> AsyncGenerator[None, None]:
413413
r"ignore"
414414
r":(async )?generator function lifespans are deprecated, use an "
415415
r"@contextlib\.asynccontextmanager function instead"
416-
r":DeprecationWarning"
416+
r":starlette.exceptions.StarletteDeprecationWarning"
417417
r":starlette.routing"
418418
)
419419

tests/test_status.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import pytest
44

5+
from starlette.exceptions import StarletteDeprecationWarning
6+
57

68
@pytest.mark.parametrize(
79
"constant,msg",
@@ -17,7 +19,7 @@
1719
),
1820
)
1921
def test_deprecated_types(constant: str, msg: str) -> None:
20-
with pytest.warns(DeprecationWarning) as record:
22+
with pytest.warns(StarletteDeprecationWarning) as record:
2123
getattr(importlib.import_module("starlette.status"), constant)
2224
assert len(record) == 1
2325
assert msg in str(record.list[0])

tests/test_testclient.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import trio.lowlevel
1515

1616
from starlette.applications import Starlette
17+
from starlette.exceptions import StarletteDeprecationWarning
1718
from starlette.middleware import Middleware
1819
from starlette.requests import Request
1920
from starlette.responses import JSONResponse, RedirectResponse, Response
@@ -425,6 +426,8 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
425426

426427

427428
def test_timeout_deprecation() -> None:
428-
with pytest.deprecated_call(match="You should not use the 'timeout' argument with the TestClient."):
429+
with pytest.warns(
430+
StarletteDeprecationWarning, match="You should not use the 'timeout' argument with the TestClient."
431+
):
429432
client = TestClient(mock_service)
430433
client.get("/", timeout=1)

0 commit comments

Comments
 (0)