]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
*: Remove most typing.TYPE_CHECKING guards and F401 noqa comments
authorBen Darnell <ben@bendarnell.com>
Thu, 19 Mar 2026 19:03:46 +0000 (15:03 -0400)
committerBen Darnell <ben@bendarnell.com>
Thu, 19 Mar 2026 22:33:18 +0000 (18:33 -0400)
Flake8 now understands type annotations and no longer emits
"unused import" warnings for type imports. Most imports that
were previously behind TYPE_CHECKING guards are no longer
needed, or can be moved to unguarded imports.

32 files changed:
tornado/curl_httpclient.py
tornado/gen.py
tornado/httpserver.py
tornado/httputil.py
tornado/ioloop.py
tornado/iostream.py
tornado/locks.py
tornado/platform/caresresolver.py
tornado/platform/twisted.py
tornado/process.py
tornado/queues.py
tornado/simple_httpclient.py
tornado/tcpclient.py
tornado/tcpserver.py
tornado/template.py
tornado/test/escape_test.py
tornado/test/gen_test.py
tornado/test/http1connection_test.py
tornado/test/httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/ioloop_test.py
tornado/test/locks_test.py
tornado/test/options_test.py
tornado/test/routing_test.py
tornado/test/simple_httpclient_test.py
tornado/test/tcpclient_test.py
tornado/test/template_test.py
tornado/testing.py
tornado/util.py
tornado/web.py
tornado/websocket.py
tornado/wsgi.py

index fd20fc0903c5514dbdb23fda80a243c7f22d290d..8d0b8814f93c57d2176a59a90bf61ee0904425b1 100644 (file)
@@ -41,10 +41,6 @@ from tornado.log import app_log
 
 from typing import Any
 from collections.abc import Callable
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Deque, Tuple  # noqa: F401
 
 curl_log = logging.getLogger("tornado.curl_httpclient")
 
@@ -62,7 +58,7 @@ class CurlAsyncHTTPClient(AsyncHTTPClient):
         self._multi.setopt(pycurl.M_SOCKETFUNCTION, self._handle_socket)
         self._curls = [self._curl_create() for i in range(max_clients)]
         self._free_list = self._curls[:]
-        self._requests: Deque[
+        self._requests: collections.deque[
             tuple[HTTPRequest, Callable[[HTTPResponse], None], float]
         ] = collections.deque()
         self._fds: dict[int, int] = {}
index efa03d2fa7ce46f8469a99e7694f73a18c04f4b9..4e5e4cde9224dd527ef57130e2f8d94135088a29 100644 (file)
@@ -100,13 +100,9 @@ from typing import (
     Dict,
     overload,
 )
-from collections.abc import Callable
+from collections.abc import Callable, Iterable
 from collections.abc import Mapping, Awaitable, Sequence
 
-if typing.TYPE_CHECKING:
-    from typing import Deque, Optional, Set  # noqa: F401
-    from collections.abc import Iterable
-
 _T = typing.TypeVar("_T")
 
 _Yieldable = Union[
@@ -375,7 +371,7 @@ class WaitIterator:
             self._unfinished = {f: i for (i, f) in enumerate(args)}
             futures = args
 
-        self._finished: Deque[Future] = collections.deque()
+        self._finished: collections.deque[Future] = collections.deque()
         self.current_index: str | int | None = None
         self.current_future: Future | None = None
         self._running_future: Future | None = None
index ea2e2ee6416dd2a96b09d44b80abfe108aee1325..3f94a43d8f381fdc691fc18cf609a06d8fbfcb33 100644 (file)
@@ -41,9 +41,6 @@ from typing import Any
 from collections.abc import Callable
 from collections.abc import Awaitable
 
-if typing.TYPE_CHECKING:
-    from typing import Set  # noqa: F401
-
 
 class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate):
     r"""A non-blocking, single-threaded HTTP server.
index ce239adcb90edb239dd2744c6605a7f74b13a90c..66fa156b844c605fbf0c3fb0e103c4a687ba3e0a 100644 (file)
@@ -50,9 +50,10 @@ from typing import (
 from collections.abc import Iterable, Mapping, Iterator, Awaitable, Generator
 
 if typing.TYPE_CHECKING:
-    from typing import Deque  # noqa: F401
-    from asyncio import Future  # noqa: F401
-    import unittest  # noqa: F401
+    # These are relatively heavy imports and aren't needed in this file
+    # unless we're type-checking.
+    from asyncio import Future
+    import unittest
 
 # To be used with str.strip() and related methods.
 HTTP_WHITESPACE = " \t"
index 1e5b42aa7eaf190b4f4a52ea813743fe15c400ae..e7564de7c6f32487a02792822a63c2733a48ad9b 100644 (file)
@@ -49,17 +49,10 @@ from tornado.log import app_log
 from tornado.util import Configurable, TimeoutError, import_object
 
 import typing
-from typing import Any, TypeVar
+from typing import Any, TypeVar, TypedDict, Protocol
 from collections.abc import Callable
 from collections.abc import Awaitable
 
-if typing.TYPE_CHECKING:
-    from typing import Dict, List, Set, TypedDict  # noqa: F401
-
-    from typing_extensions import Protocol
-else:
-    Protocol = object
-
 
 class _Selectable(Protocol):
     def fileno(self) -> int:
@@ -493,12 +486,11 @@ class IOLoop(Configurable):
         .. versionchanged:: 6.2
            ``tornado.util.TimeoutError`` is now an alias to ``asyncio.TimeoutError``.
         """
-        if typing.TYPE_CHECKING:
 
-            class FutureCell(TypedDict):
-                # noqa: F841
-                future: Future | None
-                timeout_called: bool
+        class FutureCell(TypedDict):
+            # noqa: F841
+            future: Future | None
+            timeout_called: bool
 
         future_cell: FutureCell = {"future": None, "timeout_called": False}
 
index d632fe1bd8abea50cdfe6c1a38df9dc412e01a11..6585f88e8abefdc376af8cc8dc9887f3ba8265a9 100644 (file)
@@ -42,7 +42,6 @@ from tornado.util import errno_from_exception
 
 import typing
 from typing import (
-    Optional,
     Any,
     TypeVar,
 )
@@ -51,9 +50,6 @@ from collections.abc import Awaitable
 from re import Pattern
 from types import TracebackType
 
-if typing.TYPE_CHECKING:
-    from typing import Deque, List, Type  # noqa: F401
-
 _IOStreamType = TypeVar("_IOStreamType", bound="IOStream")
 
 # These errnos indicate that a connection has been abruptly terminated.
@@ -119,7 +115,9 @@ class _StreamBuffer:
 
     def __init__(self) -> None:
         # A sequence of (False, bytearray) and (True, memoryview) objects
-        self._buffers: Deque[tuple[bool, bytearray | memoryview]] = collections.deque()
+        self._buffers: collections.deque[tuple[bool, bytearray | memoryview]] = (
+            collections.deque()
+        )
         # Position in the first buffer
         self._first_pos = 0
         self._size = 0
@@ -260,7 +258,9 @@ class BaseIOStream:
         self._read_partial = False
         self._read_until_close = False
         self._read_future: Future | None = None
-        self._write_futures: Deque[tuple[int, Future[None]]] = collections.deque()
+        self._write_futures: collections.deque[tuple[int, Future[None]]] = (
+            collections.deque()
+        )
         self._close_callback: Callable[[], None] | None = None
         self._connect_future: Future[IOStream] | None = None
         # _ssl_connect_future should be defined in SSLIOStream
@@ -557,7 +557,7 @@ class BaseIOStream:
             | bool
             | BaseException
             | tuple[
-                "Optional[Type[BaseException]]",
+                type[BaseException] | None,
                 BaseException | None,
                 TracebackType | None,
             ]
index 9cc30276aa50a181c80528deb9a798eebb2d55d4..fb42d73fef5991d96bcb862c90bec9f84854bd89 100644 (file)
@@ -21,10 +21,6 @@ from tornado.concurrent import Future, future_set_result_unless_cancelled
 
 from typing import Optional, Type, Any
 from collections.abc import Awaitable
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Deque, Set  # noqa: F401
 
 __all__ = ["Condition", "Event", "Semaphore", "BoundedSemaphore", "Lock"]
 
@@ -40,7 +36,7 @@ class _TimeoutGarbageCollector:
     """
 
     def __init__(self) -> None:
-        self._waiters: Deque[Future] = collections.deque()
+        self._waiters: collections.deque[Future] = collections.deque()
         self._timeouts = 0
 
     def _garbage_collect(self) -> None:
index fb2658e2314e5d3650f6b85075304106413524fb..1e71da94f4be48bcf5c51b48df9d1fdcf0d877f5 100644 (file)
@@ -7,10 +7,8 @@ from tornado.ioloop import IOLoop
 from tornado.netutil import Resolver, is_valid_ip
 
 import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Any, List, Tuple, Dict  # noqa: F401
-    from collections.abc import Generator
+from typing import Any
+from collections.abc import Generator
 
 
 class CaresResolver(Resolver):
@@ -63,7 +61,7 @@ class CaresResolver(Resolver):
     @gen.coroutine
     def resolve(
         self, host: str, port: int, family: int = 0
-    ) -> "Generator[Any, Any, List[Tuple[int, Any]]]":
+    ) -> "Generator[Any, Any, list[tuple[int, Any]]]":
         if is_valid_ip(host):
             addresses = [host]
         else:
index 2d28de0777591d83eca2321580d2abfb50806e46..70df475fb28509cbaf66062aaf8a786da2573d6c 100644 (file)
@@ -19,7 +19,7 @@ from twisted.python import failure  # type: ignore
 from tornado.concurrent import Future, future_set_exc_info
 from tornado import gen
 
-import typing  # noqa: F401
+import typing
 
 
 def install() -> None:
index df4eb3eb363b8d4f90cce18dae0e78d561b696d7..db797e9e141df9d2d2d40fa20bc126bc74ac6f36 100644 (file)
@@ -36,13 +36,9 @@ from tornado import ioloop
 from tornado.iostream import PipeIOStream
 from tornado.log import gen_log
 
-import typing
 from typing import Any
 from collections.abc import Callable
 
-if typing.TYPE_CHECKING:
-    from typing import List  # noqa: F401
-
 # Re-export this exception for convenience.
 CalledProcessError = subprocess.CalledProcessError
 
index ddaa8dce141f4f32e6bfe8e02281f25085e5af41..22373a5590363d07bee53ae8bf8bf5269f551811 100644 (file)
@@ -35,12 +35,8 @@ from tornado import gen, ioloop
 from tornado.concurrent import Future, future_set_result_unless_cancelled
 from tornado.locks import Event
 
-from typing import TypeVar, Generic
+from typing import TypeVar, Generic, Any
 from collections.abc import Awaitable
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Deque, Tuple, Any  # noqa: F401
 
 _T = TypeVar("_T")
 
@@ -160,8 +156,10 @@ class Queue(Generic[_T]):
 
         self._maxsize = maxsize
         self._init()
-        self._getters: Deque[Future[_T]] = collections.deque([])
-        self._putters: Deque[tuple[_T, Future[None]]] = collections.deque([])
+        self._getters: collections.deque[Future[_T]] = collections.deque([])
+        self._putters: collections.deque[tuple[_T, Future[None]]] = collections.deque(
+            []
+        )
         self._unfinished_tasks = 0
         self._finished = Event()
         self._finished.set()
index d16b1dc07d535485e8b1f59673fc8aaaab6d6a0a..7bcd6885421f44dc73912ae315f883959aac1181 100644 (file)
@@ -37,10 +37,6 @@ from typing import Any, Optional, Type
 from collections.abc import Callable
 from collections.abc import Awaitable
 from types import TracebackType
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Deque, Tuple, List  # noqa: F401
 
 
 class HTTPTimeoutError(HTTPError):
@@ -129,7 +125,7 @@ class SimpleAsyncHTTPClient(AsyncHTTPClient):
     ) -> None:
         super().initialize(defaults=defaults)
         self.max_clients = max_clients
-        self.queue: Deque[
+        self.queue: collections.deque[
             tuple[object, HTTPRequest, Callable[[HTTPResponse], None]]
         ] = collections.deque()
         self.active: dict[
index 014fec68680e9cbea6b68013a867bdf14bbb92ee..590ef7f1527423907c630bb17f7a96943f1a7458 100644 (file)
@@ -20,7 +20,6 @@ import socket
 import numbers
 import datetime
 import ssl
-import typing
 
 from tornado.concurrent import Future, future_add_done_callback
 from tornado.ioloop import IOLoop
@@ -33,9 +32,6 @@ from typing import Any, Tuple
 from collections.abc import Callable
 from collections.abc import Iterator
 
-if typing.TYPE_CHECKING:
-    from typing import Set  # noqa(F401)
-
 _INITIAL_CONNECT_TIMEOUT = 0.3
 
 
index 25fab8bad8c491761fe119e26b174cc8c55654d8..7081cd752d23b64acd64b2697c38a72759ff7480 100644 (file)
@@ -33,13 +33,8 @@ from tornado.netutil import (
 from tornado import process
 from tornado.util import errno_from_exception
 
-import typing
 from typing import Any
-from collections.abc import Iterable, Awaitable
-
-if typing.TYPE_CHECKING:
-    from typing import List  # noqa: F401
-    from collections.abc import Callable
+from collections.abc import Iterable, Awaitable, Callable
 
 
 class TCPServer:
index 30952c77558776aa2c17691027bb16c8fbdec6cb..dfcff3303c187b8fe24512ef6a7dc74469cce969 100644 (file)
@@ -208,14 +208,11 @@ from tornado import escape
 from tornado.log import app_log
 from tornado.util import ObjectDict, exec_in, unicode_type
 
-from typing import Any, Optional, TextIO
+from typing import Any, Optional, TextIO, ContextManager
 from collections.abc import Callable
 from collections.abc import Iterable
 import typing
 
-if typing.TYPE_CHECKING:
-    from typing import Tuple, ContextManager  # noqa: F401
-
 _DEFAULT_AUTOESCAPE = "xhtml_escape"
 
 
index 7331e64fe9b2b594635a9eff1da964e9b18a1721..c3f3638b36db3be9f4aca2f3fd957fd0b066e31a 100644 (file)
@@ -15,7 +15,7 @@ from tornado.escape import (
 )
 from tornado.util import unicode_type
 
-from typing import List, Tuple, Union, Dict, Any  # noqa: F401
+from typing import Any
 
 linkify_tests: list[tuple[str | bytes, dict[str, Any], str]] = [
     # (input, linkify_kwargs, expected_output)
index 514dcd0de73ed377d43650e490d582ade5312e34..66043e74a608d7109949523fe28ac5af8704e65c 100644 (file)
@@ -21,11 +21,6 @@ try:
 except ImportError:
     contextvars = None  # type: ignore
 
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import List, Optional  # noqa: F401
-
 
 class GenBasicTest(AsyncTestCase):
     @gen.coroutine
index d7acfb589b6f375165b9b833efb1b5fe4a2bbf58..abb5e6cffcf85b472566c0180e7e3c4b13bee037 100644 (file)
@@ -1,5 +1,4 @@
 import socket
-import typing  # noqa(F401)
 
 from tornado.http1connection import HTTP1Connection
 from tornado.httputil import HTTPMessageDelegate
index e19db0a1a6f35d4762bc497034159c3d682f9eb4..82110fc716f3af53f5b480f089550288978b14dd 100644 (file)
@@ -9,7 +9,6 @@ from io import BytesIO
 import subprocess
 import sys
 import time
-import typing  # noqa: F401
 import unicodedata
 import unittest
 
index 99777099e16e3e7706f7e4fa49a85a734b10cb8e..6f519303ddaac3ab299aa0a74417ab838dda37f9 100644 (file)
@@ -48,9 +48,6 @@ from io import BytesIO
 
 import typing
 
-if typing.TYPE_CHECKING:
-    from typing import Dict, List  # noqa: F401
-
 
 async def read_stream_body(stream):
     """Reads an HTTP response from `stream` and returns a tuple of its
index 98c432aba219bfadd8546ed79a59b36a3fc46e13..fc7c2855fa6cdadc6f186c47395cdd5544a99503 100644 (file)
@@ -31,11 +31,6 @@ from tornado.test.util import (
 )
 from tornado.concurrent import Future
 
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import List  # noqa: F401
-
 
 class TestIOLoop(AsyncTestCase):
     def test_add_callback_return_sequence(self):
index b1f2a8e8e79437c81e6abef11f63a5348a89a22a..394600ba730902c588dbb6f0ab4c9e3f199cad7f 100644 (file)
@@ -12,7 +12,6 @@
 
 import asyncio
 from datetime import timedelta
-import typing  # noqa: F401
 import unittest
 
 from tornado import gen, locks
index 998ef6ec3be46003087fadba46a4ab72894ca1d4..3e4d1b33cb2879c183edb9ec5a57c39e37b9b115 100644 (file)
@@ -8,11 +8,6 @@ import unittest
 from tornado.options import OptionParser, Error
 from tornado.util import basestring_type
 
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import List  # noqa: F401
-
 
 class Email:
     def __init__(self, value):
index bf18eac4b21fe80d1f9dc6786a8b0cd91c19f361..efb9d4b329d2f20e36d79056301cc28cff3c0b50 100644 (file)
@@ -28,7 +28,7 @@ from tornado.testing import AsyncHTTPTestCase
 from tornado.web import Application, HTTPError, RequestHandler
 from tornado.wsgi import WSGIContainer
 
-import typing  # noqa: F401
+import typing
 
 
 class BasicRouter(Router):
index 227d4c7003099d2bbd5f66b79f5311706ddb6801..e897f79cd864e0f51df237c5bbb122618264ae8d 100644 (file)
@@ -7,7 +7,7 @@ import re
 import socket
 import ssl
 import sys
-import typing  # noqa: F401
+import typing
 
 from tornado.escape import to_unicode, utf8
 from tornado import gen, version
index 1730a55f406302c972f4f84eb0333e5916a2f38a..f90b885df8662288317ce2cc4bb546f18c4acddb 100644 (file)
@@ -18,6 +18,7 @@ import socket
 import unittest
 
 from tornado.concurrent import Future
+from tornado.iostream import IOStream
 from tornado.netutil import bind_sockets, Resolver
 from tornado.queues import Queue
 from tornado.tcpclient import TCPClient, _Connector
@@ -28,10 +29,6 @@ from tornado.gen import TimeoutError
 
 import typing
 
-if typing.TYPE_CHECKING:
-    from tornado.iostream import IOStream  # noqa: F401
-    from typing import List, Dict, Tuple  # noqa: F401
-
 # Fake address families for testing.  Used in place of AF_INET
 # and AF_INET6 because some installations do not have AF_INET6.
 AF1, AF2 = 1, 2
index d58d2088f75874d360edc4456fb6679311d8ad9e..d6f3d0240ef137727e1b3988552d817fb7d1046e 100644 (file)
@@ -6,8 +6,6 @@ from tornado.escape import utf8, native_str, to_unicode
 from tornado.template import Template, DictLoader, ParseError, Loader
 from tornado.util import ObjectDict
 
-import typing  # noqa: F401
-
 
 class TemplateTest(unittest.TestCase):
     def test_simple(self):
index 3cdbb9a526e8251dd6c58273d1ffb4d2ee6cec0e..4de6626d9582fee64a20c5e7e14f84312412ff16 100644 (file)
@@ -39,10 +39,9 @@ from collections.abc import Callable
 from collections.abc import Coroutine
 from types import TracebackType
 
-if typing.TYPE_CHECKING:
-    _ExcInfoTuple = tuple[
-        Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]
-    ]
+_ExcInfoTuple = tuple[
+    type[BaseException] | None, BaseException | None, TracebackType | None
+]
 
 
 _NON_OWNED_IOLOOPS = AsyncIOMainLoop
index 24da9509b978383820087f6d1f6530ce4683e689..9b670cfd04870df5e7d3ece25b571395ef69d8b7 100644 (file)
@@ -30,10 +30,9 @@ from re import Match
 if typing.TYPE_CHECKING:
     # Additional imports only used in type comments.
     # This lets us make these imports lazy.
-    import datetime  # noqa: F401
-    from types import TracebackType  # noqa: F401
-    from typing import Union  # noqa: F401
-    import unittest  # noqa: F401
+    import datetime
+    from types import TracebackType
+    import unittest
 
 # Aliases for types that are spelled differently in different Python
 # versions. bytes_type is deprecated and no longer used in Tornado
index 1f756eef8bb2f7236654b8b36b607f28fa3d448a..63765eed63ee2064381d680296a77dddff088c7c 100644 (file)
@@ -118,11 +118,6 @@ from typing import (
 from collections.abc import Callable
 from collections.abc import Awaitable, Iterable, Generator
 from types import TracebackType
-import typing
-
-if typing.TYPE_CHECKING:
-    from typing import Set  # noqa: F401
-
 
 # The following types are accepted by RequestHandler.set_header
 # and related methods.
index 5755c938750bd2819ccdb77129a19085d0eaf266..2578c92e96166305510f90b3078773ce1ea5bc55 100644 (file)
@@ -38,62 +38,62 @@ from tornado.tcpclient import TCPClient
 from tornado.util import _websocket_mask
 
 from typing import (
-    TYPE_CHECKING,
     cast,
     Any,
     Optional,
     Union,
     Type,
+    Protocol,
 )
 from collections.abc import Callable
 from collections.abc import Awaitable
 from types import TracebackType
 
-if TYPE_CHECKING:
-    from typing_extensions import Protocol
-
-    # The zlib compressor types aren't actually exposed anywhere
-    # publicly, so declare protocols for the portions we use.
-    class _Compressor(Protocol):
-        def compress(self, data: bytes) -> bytes:
-            pass
-
-        def flush(self, mode: int) -> bytes:
-            pass
-
-    class _Decompressor(Protocol):
-        @property
-        def unconsumed_tail(self) -> bytes:
-            pass
-
-        def decompress(self, data: bytes, max_length: int) -> bytes:
-            pass
-
-    class _WebSocketDelegate(Protocol):
-        # The common base interface implemented by WebSocketHandler on
-        # the server side and WebSocketClientConnection on the client
-        # side.
-        def on_ws_connection_close(
-            self, close_code: int | None = None, close_reason: str | None = None
-        ) -> None:
-            pass
-
-        def on_message(self, message: str | bytes) -> Optional["Awaitable[None]"]:
-            pass
-
-        def on_ping(self, data: bytes) -> None:
-            pass
-
-        def on_pong(self, data: bytes) -> None:
-            pass
-
-        def log_exception(
-            self,
-            typ: type[BaseException] | None,
-            value: BaseException | None,
-            tb: TracebackType | None,
-        ) -> None:
-            pass
+
+# The zlib compressor types aren't actually exposed anywhere
+# publicly, so declare protocols for the portions we use.
+class _Compressor(Protocol):
+    def compress(self, data: bytes) -> bytes:
+        pass
+
+    def flush(self, mode: int) -> bytes:
+        pass
+
+
+class _Decompressor(Protocol):
+    @property
+    def unconsumed_tail(self) -> bytes:
+        pass
+
+    def decompress(self, data: bytes, max_length: int) -> bytes:
+        pass
+
+
+class _WebSocketDelegate(Protocol):
+    # The common base interface implemented by WebSocketHandler on
+    # the server side and WebSocketClientConnection on the client
+    # side.
+    def on_ws_connection_close(
+        self, close_code: int | None = None, close_reason: str | None = None
+    ) -> None:
+        pass
+
+    def on_message(self, message: str | bytes) -> Optional["Awaitable[None]"]:
+        pass
+
+    def on_ping(self, data: bytes) -> None:
+        pass
+
+    def on_pong(self, data: bytes) -> None:
+        pass
+
+    def log_exception(
+        self,
+        typ: type[BaseException] | None,
+        value: BaseException | None,
+        tb: TracebackType | None,
+    ) -> None:
+        pass
 
 
 _default_max_message_size = 10 * 1024 * 1024
index e94cfc8c93cd696f7f3af5e0258cd7b56ced0d2d..692c69e45fafdc88d1dd7cf6987f1c3e14548497 100644 (file)
@@ -38,14 +38,13 @@ from tornado import httputil
 from tornado.ioloop import IOLoop
 from tornado.log import access_log
 
-from typing import Optional, Any
+from typing import Any
 from collections.abc import Callable
 from types import TracebackType
 import typing
 
 if typing.TYPE_CHECKING:
-    from typing import Type  # noqa: F401
-    from _typeshed.wsgi import WSGIApplication as WSGIAppType  # noqa: F401
+    from _typeshed.wsgi import WSGIApplication as WSGIAppType
 
 
 # PEP 3333 specifies that WSGI on python 3 generally deals with byte strings
@@ -143,7 +142,7 @@ class WSGIContainer:
             headers: list[tuple[str, str]],
             exc_info: None | (
                 tuple[
-                    "Optional[Type[BaseException]]",
+                    type[BaseException] | None,
                     BaseException | None,
                     TracebackType | None,
                 ]