Skip to content

Commit 3b7fa76

Browse files
committed
Enable deprecation for second argument of handlers.
1 parent 96fddaf commit 3b7fa76

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

docs/project/changelog.rst

+20-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ Backwards-incompatible changes
4343

4444
For backwards compatibility, ``ssl_context`` is still supported.
4545

46+
.. admonition:: Receiving the request path in the second parameter of connection
47+
handlers is deprecated.
48+
:class: note
49+
50+
If you implemented the connection handler of a server as::
51+
52+
async def handler(request, path):
53+
...
54+
55+
You should switch to the recommended pattern since 10.1::
56+
57+
async def handler(request):
58+
path = request.path # only if handler() uses the path argument
59+
...
60+
4661
New features
4762
............
4863

@@ -257,20 +272,19 @@ New features
257272

258273
* Added a tutorial.
259274

260-
* Made the second parameter of connection handlers optional. It will be
261-
deprecated in the next major release. The request path is available in
262-
the :attr:`~legacy.protocol.WebSocketCommonProtocol.path` attribute of
263-
the first argument.
275+
* Made the second parameter of connection handlers optional. The request path is
276+
available in the :attr:`~legacy.protocol.WebSocketCommonProtocol.path`
277+
attribute of the first argument.
264278

265279
If you implemented the connection handler of a server as::
266280

267281
async def handler(request, path):
268282
...
269283

270-
You should replace it by::
284+
You should replace it with::
271285

272286
async def handler(request):
273-
path = request.path # if handler() uses the path argument
287+
path = request.path # only if handler() uses the path argument
274288
...
275289

276290
* Added ``python -m websockets --version``.

src/websockets/legacy/server.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1168,9 +1168,7 @@ def remove_path_argument(
11681168
pass
11691169
else:
11701170
# ws_handler accepts two arguments; activate backwards compatibility.
1171-
1172-
# Enable deprecation warning and announce deprecation in 11.0.
1173-
# warnings.warn("remove second argument of ws_handler", DeprecationWarning)
1171+
warnings.warn("remove second argument of ws_handler", DeprecationWarning)
11741172

11751173
async def _ws_handler(websocket: WebSocketServerProtocol) -> Any:
11761174
return await cast(

tests/legacy/test_client_server.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,7 @@ async def handler_with_path(ws, path):
480480

481481
with self.temp_server(
482482
handler=handler_with_path,
483-
# Enable deprecation warning and announce deprecation in 11.0.
484-
# deprecation_warnings=["remove second argument of ws_handler"],
483+
deprecation_warnings=["remove second argument of ws_handler"],
485484
):
486485
with self.temp_client("/path"):
487486
self.assertEqual(
@@ -497,8 +496,7 @@ async def handler_with_path(ws, path, extra):
497496

498497
with self.temp_server(
499498
handler=bound_handler_with_path,
500-
# Enable deprecation warning and announce deprecation in 11.0.
501-
# deprecation_warnings=["remove second argument of ws_handler"],
499+
deprecation_warnings=["remove second argument of ws_handler"],
502500
):
503501
with self.temp_client("/path"):
504502
self.assertEqual(

0 commit comments

Comments
 (0)