]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Use variable annotations to avoid None defaults (#3575)
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>
Wed, 18 Mar 2026 19:36:28 +0000 (12:36 -0700)
committerGitHub <noreply@github.com>
Wed, 18 Mar 2026 19:36:28 +0000 (15:36 -0400)
PEP 526 landed in Python 3.5 which is quite dead now

tornado/httpclient.py
tornado/httputil.py
tornado/iostream.py
tornado/netutil.py
tornado/test/web_test.py
tornado/util.py
tornado/web.py
tornado/websocket.py

index 488fe6de0b0832c49483e0e89caec18ff5832b14..e3023baeaaa748b1b2f887466e8c4cb8bfd1dc0f 100644 (file)
@@ -176,7 +176,7 @@ class AsyncHTTPClient(Configurable):
 
     """
 
-    _instance_cache = None  # type: Dict[IOLoop, AsyncHTTPClient]
+    _instance_cache: Dict[IOLoop, "AsyncHTTPClient"]
 
     @classmethod
     def configurable_base(cls) -> Type[Configurable]:
@@ -339,7 +339,7 @@ class AsyncHTTPClient(Configurable):
 class HTTPRequest:
     """HTTP client request object."""
 
-    _headers = None  # type: Union[Dict[str, str], httputil.HTTPHeaders]
+    _headers: Union[Dict[str, str], httputil.HTTPHeaders]
 
     # Default values for HTTPRequest parameters.
     # Merged with the values on the request object by AsyncHTTPClient
@@ -626,7 +626,7 @@ class HTTPResponse:
     # I'm not sure why these don't get type-inferred from the references in __init__.
     error = None  # type: Optional[BaseException]
     _error_is_response_code = False
-    request = None  # type: HTTPRequest
+    request: HTTPRequest
 
     def __init__(
         self,
index 38d9f8799c8cfedcea11fe0013d7069e765ff1ba..3ffba7ecfb35b5bb09791955b1bdf8a29c5ce5a0 100644 (file)
@@ -475,11 +475,11 @@ class HTTPServerRequest:
        temporarily restored in 6.5.2.
     """
 
-    path = None  # type: str
-    query = None  # type: str
+    path: str
+    query: str
 
     # HACK: Used for stream_request_body
-    _body_future = None  # type: Future[None]
+    _body_future: "Future[None]"
 
     def __init__(
         self,
index dd2111e3b8f269c9bebb8eeb4bc96ea13793b7f6..44e96cd5013730ae43c27520bd21d7f0f1a31b88 100644 (file)
@@ -1324,7 +1324,7 @@ class SSLIOStream(IOStream):
     wrapped when `IOStream.connect` is finished.
     """
 
-    socket = None  # type: ssl.SSLSocket
+    socket: ssl.SSLSocket
 
     def __init__(self, *args: Any, **kwargs: Any) -> None:
         """The ``ssl_options`` keyword argument may either be an
index 3ec76af77c4180c7a53bc597e9471651503b000a..a426c346c32c49e0987e442bc5c1e6e6df8a2b45 100644 (file)
@@ -515,8 +515,8 @@ class ThreadedResolver(ExecutorResolver):
        of this class.
     """
 
-    _threadpool = None  # type: ignore
-    _threadpool_pid = None  # type: int
+    _threadpool: Optional[concurrent.futures.ThreadPoolExecutor] = None
+    _threadpool_pid: Optional[int] = None
 
     def initialize(self, num_threads: int = 10) -> None:  # type: ignore
         threadpool = ThreadedResolver._create_threadpool(num_threads)
index a7886795d5657b9120a129280b2696a7ecb75dd5..f3d6013bea0d99600f3ec750173a045a98ffacb4 100644 (file)
@@ -223,7 +223,7 @@ class SecureCookieV2Test(unittest.TestCase):
 
 
 class FinalReturnTest(WebTestCase):
-    final_return = None  # type: Future
+    final_return: Future
 
     def get_handlers(self):
         test = self
index 19df4913232b4055ae130ef871516f8b918e5947..ee721b2e00e6b85006e5b0a542230b7bcfc68299 100644 (file)
@@ -236,8 +236,8 @@ class Configurable:
     # There may be a clever way to use generics here to get more
     # precise types (i.e. for a particular Configurable subclass T,
     # all the types are subclasses of T, not just Configurable).
-    __impl_class = None  # type: Optional[Type[Configurable]]
-    __impl_kwargs = None  # type: Dict[str, Any]
+    __impl_class: Optional[Type["Configurable"]] = None
+    __impl_kwargs: Optional[Dict[str, Any]] = None
 
     def __new__(cls, *args: Any, **kwargs: Any) -> Any:
         base = cls.configurable_base()
@@ -324,13 +324,13 @@ class Configurable:
 
     @classmethod
     def _save_configuration(cls):
-        # type: () -> Tuple[Optional[Type[Configurable]], Dict[str, Any]]
+        # type: () -> Tuple[Optional[Type[Configurable]], Optional[Dict[str, Any]]]
         base = cls.configurable_base()
         return (base.__impl_class, base.__impl_kwargs)
 
     @classmethod
     def _restore_configuration(cls, saved):
-        # type: (Tuple[Optional[Type[Configurable]], Dict[str, Any]]) -> None
+        # type: (Tuple[Optional[Type[Configurable]], Optional[Dict[str, Any]]]) -> None
         base = cls.configurable_base()
         base.__impl_class = saved[0]
         base.__impl_kwargs = saved[1]
index c3efdbd56fe9097c3f863b4105a11a889bbc33b6..48b3560e6224be247f8016668c50d52cdd0ec085 100644 (file)
@@ -205,9 +205,9 @@ class RequestHandler:
     _stream_request_body = False
 
     # Will be set in _execute.
-    _transforms = None  # type: List[OutputTransform]
-    path_args = None  # type: List[str]
-    path_kwargs = None  # type: Dict[str, str]
+    _transforms: List["OutputTransform"]
+    path_args: List[str]
+    path_kwargs: Dict[str, str]
 
     def __init__(
         self,
index ab9b76f5e929f1d0d495a6c181d57f9cac9f45b8..4e5843cb1ba0f917bffbe2a7ae3ab1bcb211ae28 100644 (file)
@@ -834,7 +834,7 @@ class WebSocketProtocol13(WebSocketProtocol):
     RSV_MASK = RSV1 | RSV2 | RSV3
     OPCODE_MASK = 0x0F
 
-    stream = None  # type: IOStream
+    stream: IOStream
 
     def __init__(
         self,
@@ -1396,7 +1396,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
     `websocket_connect` function instead.
     """
 
-    protocol = None  # type: WebSocketProtocol
+    protocol: Optional[WebSocketProtocol] = None
 
     def __init__(
         self,
@@ -1620,6 +1620,7 @@ class WebSocketClientConnection(simple_httpclient._HTTPConnection):
 
         .. versionadded:: 5.1
         """
+        assert self.protocol is not None
         return self.protocol.selected_subprotocol
 
     def log_exception(