From b240a987245cb8d47f1ca34408d21ad148069112 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Thu, 22 May 2025 16:18:09 -0400 Subject: [PATCH] Update python dependencies Notably including mypy, which required some updates to various code files to improve type annotations. --- docs/conf.py | 3 -- requirements.txt | 64 ++++++++++++++++++---------------- tornado/curl_httpclient.py | 2 +- tornado/gen.py | 4 +-- tornado/process.py | 2 -- tornado/tcpclient.py | 5 ++- tornado/test/__main__.py | 3 +- tornado/test/ioloop_test.py | 2 +- tornado/test/web_test.py | 8 ++--- tornado/test/websocket_test.py | 8 ++--- tornado/util.py | 2 +- tornado/websocket.py | 28 ++++++++------- 12 files changed, 65 insertions(+), 66 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index c2c81b5f..ce766675 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,8 +2,6 @@ import os import sphinx.errors import sys -import sphinx_rtd_theme - # Ensure we get the local copy of tornado instead of what's on the standard path sys.path.insert(0, os.path.abspath("..")) import tornado @@ -88,7 +86,6 @@ latex_documents = [ intersphinx_mapping = {"python": ("https://docs.python.org/3/", None)} html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Suppress warnings about "class reference target not found" for these types. # In most cases these types come from type annotations and are for mypy's use. diff --git a/requirements.txt b/requirements.txt index b32a5562..5f450911 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,31 +4,31 @@ # # pip-compile # -alabaster==0.7.16 +alabaster==1.0.0 # via sphinx -babel==2.15.0 +babel==2.17.0 # via sphinx -black==24.4.2 +black==25.1.0 # via -r requirements.in -build==1.2.1 +build==1.2.2.post1 # via pip-tools cachetools==5.5.2 # via tox -certifi==2024.7.4 +certifi==2025.4.26 # via requests chardet==5.2.0 # via tox -charset-normalizer==3.3.2 +charset-normalizer==3.4.2 # via requests -click==8.1.7 +click==8.2.1 # via # black # pip-tools colorama==0.4.6 # via tox -distlib==0.3.8 +distlib==0.3.9 # via virtualenv -docutils==0.20.1 +docutils==0.21.2 # via # sphinx # sphinx-rtd-theme @@ -36,21 +36,21 @@ filelock==3.18.0 # via # tox # virtualenv -flake8==7.0.0 +flake8==7.2.0 # via -r requirements.in -idna==3.7 +idna==3.10 # via requests imagesize==1.4.1 # via sphinx jinja2==3.1.6 # via sphinx -markupsafe==2.1.5 +markupsafe==3.0.2 # via jinja2 mccabe==0.7.0 # via flake8 -mypy==1.10.0 +mypy==1.15.0 # via -r requirements.in -mypy-extensions==1.0.0 +mypy-extensions==1.1.0 # via # black # mypy @@ -70,56 +70,58 @@ platformdirs==4.3.8 # black # tox # virtualenv -pluggy==1.5.0 +pluggy==1.6.0 # via tox -pycodestyle==2.11.1 +pycodestyle==2.13.0 # via flake8 -pyflakes==3.2.0 +pyflakes==3.3.2 # via flake8 -pygments==2.18.0 +pygments==2.19.1 # via sphinx pyproject-api==1.9.1 # via tox -pyproject-hooks==1.1.0 +pyproject-hooks==1.2.0 # via # build # pip-tools requests==2.32.3 # via sphinx -snowballstemmer==2.2.0 +roman-numerals-py==3.1.0 # via sphinx -sphinx==7.3.7 +snowballstemmer==3.0.1 + # via sphinx +sphinx==8.2.3 # via # -r requirements.in # sphinx-rtd-theme # sphinxcontrib-jquery -sphinx-rtd-theme==2.0.0 +sphinx-rtd-theme==3.0.2 # via -r requirements.in -sphinxcontrib-applehelp==1.0.8 +sphinxcontrib-applehelp==2.0.0 # via sphinx -sphinxcontrib-devhelp==1.0.6 +sphinxcontrib-devhelp==2.0.0 # via sphinx -sphinxcontrib-htmlhelp==2.0.5 +sphinxcontrib-htmlhelp==2.1.0 # via sphinx sphinxcontrib-jquery==4.1 # via sphinx-rtd-theme sphinxcontrib-jsmath==1.0.1 # via sphinx -sphinxcontrib-qthelp==1.0.7 +sphinxcontrib-qthelp==2.0.0 # via sphinx -sphinxcontrib-serializinghtml==1.1.10 +sphinxcontrib-serializinghtml==2.0.0 # via sphinx tox==4.26.0 # via -r requirements.in -types-pycurl==7.45.3.20240421 +types-pycurl==7.45.6.20250309 # via -r requirements.in -typing-extensions==4.12.2 +typing-extensions==4.13.2 # via mypy -urllib3==2.2.2 +urllib3==2.4.0 # via requests virtualenv==20.31.2 # via tox -wheel==0.43.0 +wheel==0.45.1 # via pip-tools # The following packages are considered to be unsafe in a requirements file: diff --git a/tornado/curl_httpclient.py b/tornado/curl_httpclient.py index dde70032..eb3fa783 100644 --- a/tornado/curl_httpclient.py +++ b/tornado/curl_httpclient.py @@ -544,7 +544,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient): def _curl_header_callback( self, headers: httputil.HTTPHeaders, - header_callback: Callable[[str], None], + header_callback: Optional[Callable[[str], None]], header_line_bytes: bytes, ) -> None: header_line = native_str(header_line_bytes.decode("latin1")) diff --git a/tornado/gen.py b/tornado/gen.py index 3dab733c..1ee8b608 100644 --- a/tornado/gen.py +++ b/tornado/gen.py @@ -171,7 +171,7 @@ def _fake_ctx_run(f: Callable[..., _T], *args: Any, **kw: Any) -> _T: @overload def coroutine( - func: Callable[..., "Generator[Any, Any, _T]"] + func: Callable[..., "Generator[Any, Any, _T]"], ) -> Callable[..., "Future[_T]"]: ... @@ -180,7 +180,7 @@ def coroutine(func: Callable[..., _T]) -> Callable[..., "Future[_T]"]: ... def coroutine( - func: Union[Callable[..., "Generator[Any, Any, _T]"], Callable[..., _T]] + func: Union[Callable[..., "Generator[Any, Any, _T]"], Callable[..., _T]], ) -> Callable[..., "Future[_T]"]: """Decorator for asynchronous generators. diff --git a/tornado/process.py b/tornado/process.py index 339ef659..61700c58 100644 --- a/tornado/process.py +++ b/tornado/process.py @@ -117,7 +117,6 @@ def fork_processes( if max_restarts is None: max_restarts = 100 - global _task_id assert _task_id is None if num_processes is None or num_processes <= 0: num_processes = cpu_count() @@ -181,7 +180,6 @@ def task_id() -> Optional[int]: Returns None if this process was not created by `fork_processes`. """ - global _task_id return _task_id diff --git a/tornado/tcpclient.py b/tornado/tcpclient.py index 2e4b2848..5b2a9f3f 100644 --- a/tornado/tcpclient.py +++ b/tornado/tcpclient.py @@ -13,8 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -"""A non-blocking TCP connection factory. -""" +"""A non-blocking TCP connection factory.""" import functools import socket @@ -296,7 +295,7 @@ class TCPClient: def _create_stream( self, - max_buffer_size: int, + max_buffer_size: Optional[int], af: socket.AddressFamily, addr: Tuple, source_ip: Optional[str] = None, diff --git a/tornado/test/__main__.py b/tornado/test/__main__.py index 65b794d9..eb52caf1 100644 --- a/tornado/test/__main__.py +++ b/tornado/test/__main__.py @@ -1,5 +1,4 @@ -"""Shim to allow python -m tornado.test. -""" +"""Shim to allow python -m tornado.test.""" from tornado.test.runtests import all, main diff --git a/tornado/test/ioloop_test.py b/tornado/test/ioloop_test.py index 37ac6deb..c1e2df6a 100644 --- a/tornado/test/ioloop_test.py +++ b/tornado/test/ioloop_test.py @@ -555,7 +555,7 @@ class TestIOLoopFutures(AsyncTestCase): count = [0] class MyExecutor(futures.ThreadPoolExecutor): - def submit(self, func, *args): + def submit(self, func, *args): # type: ignore[override] count[0] += 1 return super().submit(func, *args) diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index a514e2a4..9ab054b3 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -53,7 +53,7 @@ import logging import os import re import socket -import typing # noqa: F401 +import typing import unittest import urllib.parse @@ -111,10 +111,10 @@ class CookieTestRequestHandler(RequestHandler): settings=dict(cookie_secret=cookie_secret, key_version=key_version) ) - def get_cookie(self, name): - return self._cookies.get(name) + def get_cookie(self, name) -> typing.Optional[str]: # type: ignore[override] + return to_unicode(self._cookies.get(name)) - def set_cookie(self, name, value, expires_days=None): + def set_cookie(self, name, value, expires_days=None): # type: ignore[override] self._cookies[name] = value diff --git a/tornado/test/websocket_test.py b/tornado/test/websocket_test.py index 1f317fb0..275fcaee 100644 --- a/tornado/test/websocket_test.py +++ b/tornado/test/websocket_test.py @@ -141,7 +141,7 @@ class PathArgsHandler(TestWebSocketHandler): class CoroutineOnMessageHandler(TestWebSocketHandler): - def initialize(self, **kwargs): + def initialize(self, **kwargs): # type: ignore[override] super().initialize(**kwargs) self.sleeping = 0 @@ -161,7 +161,7 @@ class RenderMessageHandler(TestWebSocketHandler): class SubprotocolHandler(TestWebSocketHandler): - def initialize(self, **kwargs): + def initialize(self, **kwargs): # type: ignore[override] super().initialize(**kwargs) self.select_subprotocol_called = False @@ -180,7 +180,7 @@ class SubprotocolHandler(TestWebSocketHandler): class OpenCoroutineHandler(TestWebSocketHandler): - def initialize(self, test, **kwargs): + def initialize(self, test, **kwargs): # type: ignore[override] super().initialize(**kwargs) self.test = test self.open_finished = False @@ -634,7 +634,7 @@ class WebSocketTest(WebSocketBaseTestCase): class NativeCoroutineOnMessageHandler(TestWebSocketHandler): - def initialize(self, **kwargs): + def initialize(self, **kwargs): # type: ignore[override] super().initialize(**kwargs) self.sleeping = 0 diff --git a/tornado/util.py b/tornado/util.py index 2e5eee79..19df4913 100644 --- a/tornado/util.py +++ b/tornado/util.py @@ -145,7 +145,7 @@ def exec_in( def raise_exc_info( - exc_info: Tuple[Optional[type], Optional[BaseException], Optional["TracebackType"]] + exc_info: Tuple[Optional[type], Optional[BaseException], Optional["TracebackType"]], ) -> typing.NoReturn: try: if exc_info[1] is not None: diff --git a/tornado/websocket.py b/tornado/websocket.py index b719547b..95d78029 100644 --- a/tornado/websocket.py +++ b/tornado/websocket.py @@ -65,7 +65,9 @@ if TYPE_CHECKING: pass class _Decompressor(Protocol): - unconsumed_tail = b"" # type: bytes + @property + def unconsumed_tail(self) -> bytes: + pass def decompress(self, data: bytes, max_length: int) -> bytes: pass @@ -420,21 +422,23 @@ class WebSocketHandler(tornado.web.RequestHandler): # TODO: Add wbits option. return None - def open(self, *args: str, **kwargs: str) -> Optional[Awaitable[None]]: - """Invoked when a new WebSocket is opened. + def _open(self, *args: str, **kwargs: str) -> Optional[Awaitable[None]]: + pass - The arguments to `open` are extracted from the `tornado.web.URLSpec` - regular expression, just like the arguments to - `tornado.web.RequestHandler.get`. + open = _open # type: Callable[..., Optional[Awaitable[None]]] + """Invoked when a new WebSocket is opened. - `open` may be a coroutine. `on_message` will not be called until - `open` has returned. + The arguments to `open` are extracted from the `tornado.web.URLSpec` + regular expression, just like the arguments to + `tornado.web.RequestHandler.get`. - .. versionchanged:: 5.1 + `open` may be a coroutine. `on_message` will not be called until + `open` has returned. - ``open`` may be a coroutine. - """ - pass + .. versionchanged:: 5.1 + + ``open`` may be a coroutine. + """ def on_message(self, message: Union[str, bytes]) -> Optional[Awaitable[None]]: """Handle incoming messages on the WebSocket -- 2.47.3