Skip to content

Commit 1161f9b

Browse files
authored
Merge pull request #3486 from bdarnell/websocket-deprecate-callback
websocket: deprecate callback argument to websocket_connect
2 parents 9fe010f + abbc070 commit 1161f9b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

tornado/test/websocket_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from tornado.netutil import Resolver
1515
from tornado.simple_httpclient import SimpleAsyncHTTPClient
1616
from tornado.template import DictLoader
17-
from tornado.test.util import abstract_base_test
17+
from tornado.test.util import abstract_base_test, ignore_deprecation
1818
from tornado.testing import AsyncHTTPTestCase, gen_test, bind_unused_port, ExpectLog
1919
from tornado.web import Application, RequestHandler
2020

@@ -333,9 +333,10 @@ def test_websocket_gen(self):
333333
self.assertEqual(response, "hello")
334334

335335
def test_websocket_callbacks(self):
336-
websocket_connect(
337-
"ws://127.0.0.1:%d/echo" % self.get_http_port(), callback=self.stop
338-
)
336+
with ignore_deprecation():
337+
websocket_connect(
338+
"ws://127.0.0.1:%d/echo" % self.get_http_port(), callback=self.stop
339+
)
339340
ws = self.wait().result()
340341
ws.write_message("hello")
341342
ws.read_message(self.stop)

tornado/websocket.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,11 @@ def websocket_connect(
16751675
16761676
.. versionchanged:: 6.3
16771677
Added the ``resolver`` argument.
1678+
1679+
.. deprecated:: 6.5
1680+
The ``callback`` argument is deprecated and will be removed in Tornado 7.0.
1681+
Use the returned Future instead. Note that ``on_message_callback`` is not
1682+
deprecated and may still be used.
16781683
"""
16791684
if isinstance(url, httpclient.HTTPRequest):
16801685
assert connect_timeout is None
@@ -1699,5 +1704,11 @@ def websocket_connect(
16991704
resolver=resolver,
17001705
)
17011706
if callback is not None:
1707+
warnings.warn(
1708+
"The callback argument to websocket_connect is deprecated. "
1709+
"Use the returned Future instead.",
1710+
DeprecationWarning,
1711+
stacklevel=2,
1712+
)
17021713
IOLoop.current().add_future(conn.connect_future, callback)
17031714
return conn.connect_future

0 commit comments

Comments
 (0)