]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
upgrade mypy to 0.941 (#3123)
authorThomas Grainger <tagrain@gmail.com>
Fri, 18 Mar 2022 20:17:50 +0000 (20:17 +0000)
committerGitHub <noreply@github.com>
Fri, 18 Mar 2022 20:17:50 +0000 (16:17 -0400)
12 files changed:
maint/requirements.in
maint/requirements.txt
tornado/httputil.py
tornado/test/__init__.py [new file with mode: 0644]
tornado/test/gettext_translations/extract_me.py
tornado/test/httpclient_test.py
tornado/test/ioloop_test.py
tornado/test/iostream_test.py
tornado/test/tcpserver_test.py
tornado/test/testing_test.py
tornado/testing.py
tornado/wsgi.py

index 3f704d00cca47351ede923db12f2b4f168628daf..ea67be01e8282f2bbcbb0ef61e8f096444991446 100644 (file)
@@ -9,5 +9,6 @@
 
 black
 flake8
-mypy
+mypy>=0.941
+types-pycurl
 tox
index d4ddf7ccf3978ab78983ece7819ff0526888b411..e2b3564e45746d42830ab388d923a300c59a5644 100644 (file)
@@ -5,8 +5,8 @@ distlib==0.3.1
 filelock==3.0.12
 flake8==3.8.4
 mccabe==0.6.1
+mypy==0.941
 mypy-extensions==0.4.3
-mypy==0.790
 packaging==20.4
 pathspec==0.8.0
 pluggy==0.13.1
@@ -17,7 +17,9 @@ pyparsing==2.4.7
 regex==2020.10.28
 six==1.15.0
 toml==0.10.1
+tomli==2.0.1
 tox==3.20.1
 typed-ast==1.4.1
-typing-extensions==3.7.4.3
+types-pycurl==7.44.7
+typing-extensions==4.1.1
 virtualenv==20.1.0
index 12313f351c5cafb0f5cb094a9f689a91d5fe1af2..9c341d47cc2a88d8588da7d622cd9422514edfa5 100644 (file)
@@ -408,7 +408,7 @@ class HTTPServerRequest(object):
 
     def full_url(self) -> str:
         """Reconstructs the full URL for this request."""
-        return self.protocol + "://" + self.host + self.uri
+        return self.protocol + "://" + self.host + self.uri  # type: ignore[operator]
 
     def request_time(self) -> float:
         """Returns the amount of time it took for this request to execute."""
diff --git a/tornado/test/__init__.py b/tornado/test/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 08b29bc53cb2695bf349d90cbcc94be04b32edd8..860e3d1b2aa19d79deb70d7ebd67be2acc9e48bd 100644 (file)
@@ -8,8 +8,8 @@
 # 3) msgfmt tornado_test.po -o tornado_test.mo
 # 4) Put the file in the proper location: $LANG/LC_MESSAGES
 
-_("school")
-pgettext("law", "right")
-pgettext("good", "right")
-pgettext("organization", "club", "clubs", 1)
-pgettext("stick", "club", "clubs", 1)
+_("school")  # type: ignore[name-defined]
+pgettext("law", "right")  # type: ignore[name-defined]
+pgettext("good", "right")  # type: ignore[name-defined]
+pgettext("organization", "club", "clubs", 1)  # type: ignore[name-defined]
+pgettext("stick", "club", "clubs", 1)  # type: ignore[name-defined]
index af5e018970272987f1522fc3f4fbc29dc0c29219..ab93067f5e3462e6a526cc5f180843a91b0b6362 100644 (file)
@@ -139,15 +139,15 @@ class SetHeaderHandler(RequestHandler):
 
 
 class InvalidGzipHandler(RequestHandler):
-    def get(self):
+    def get(self) -> None:
         # set Content-Encoding manually to avoid automatic gzip encoding
         self.set_header("Content-Type", "text/plain")
         self.set_header("Content-Encoding", "gzip")
         # Triggering the potential bug seems to depend on input length.
         # This length is taken from the bad-response example reported in
         # https://github.com/tornadoweb/tornado/pull/2875 (uncompressed).
-        body = "".join("Hello World {}\n".format(i) for i in range(9000))[:149051]
-        body = gzip.compress(body.encode(), compresslevel=6) + b"\00"
+        text = "".join("Hello World {}\n".format(i) for i in range(9000))[:149051]
+        body = gzip.compress(text.encode(), compresslevel=6) + b"\00"
         self.write(body)
 
 
index c28516506ba7f9a4fde3b53b3da1d6d8630fb986..825f5a2a5323f34637039d81c2814c9dee3cdb67 100644 (file)
@@ -1,5 +1,6 @@
 from concurrent.futures import ThreadPoolExecutor
 from concurrent import futures
+from collections.abc import Generator
 import contextlib
 import datetime
 import functools
@@ -28,6 +29,7 @@ from tornado.test.util import (
     skipIfNonUnix,
     skipOnTravis,
 )
+from tornado.concurrent import Future
 
 import typing
 
@@ -725,12 +727,11 @@ class TestPeriodicCallbackAsync(AsyncTestCase):
         pc.stop()
         self.assertEqual(count, 3)
 
-    def test_periodic_coro(self):
+    def test_periodic_coro(self) -> None:
         counts = [0, 0]
-        pc = None
 
         @gen.coroutine
-        def callback() -> None:
+        def callback() -> "Generator[Future[None], object, None]":
             counts[0] += 1
             yield gen.sleep(0.025)
             counts[1] += 1
@@ -744,9 +745,8 @@ class TestPeriodicCallbackAsync(AsyncTestCase):
         self.assertEqual(counts[0], 3)
         self.assertEqual(counts[1], 3)
 
-    def test_periodic_async(self):
+    def test_periodic_async(self) -> None:
         counts = [0, 0]
-        pc = None
 
         async def callback() -> None:
             counts[0] += 1
index b098c9aacdd863d6b1acf8e578d14b7e4e68e0c4..e22e83e60faac8e6fa3318eb9c31809b1c24d7dc 100644 (file)
@@ -816,7 +816,10 @@ class TestIOStreamMixin(TestReadWriteMixin):
         # windows, making this check redundant with skipIfNonUnix, but
         # we sometimes enable it on other platforms for testing.
         io_loop = IOLoop.current()
-        if isinstance(io_loop.selector_loop, AddThreadSelectorEventLoop):
+        if isinstance(
+            io_loop.selector_loop,  # type: ignore[attr-defined]
+            AddThreadSelectorEventLoop,
+        ):
             self.skipTest("AddThreadSelectorEventLoop not supported")
         server, client = yield self.make_iostream_pair()
         try:
index 7c75acf6bcf97cc6d1966652d8962d2c76937a02..fc9e98a23a15623d14c1695df8079090496945cc 100644 (file)
@@ -4,7 +4,6 @@ import sys
 import textwrap
 import unittest
 
-from tornado.escape import utf8, to_unicode
 from tornado import gen
 from tornado.iostream import IOStream
 from tornado.log import app_log
@@ -122,20 +121,20 @@ class TestMultiprocess(unittest.TestCase):
     # processes, each of which prints its task id to stdout (a single
     # byte, so we don't have to worry about atomicity of the shared
     # stdout stream) and then exits.
-    def run_subproc(self, code):
-        proc = subprocess.Popen(
-            sys.executable, stdin=subprocess.PIPE, stdout=subprocess.PIPE
-        )
-        proc.stdin.write(utf8(code))
-        proc.stdin.close()
-        proc.wait()
-        stdout = proc.stdout.read()
-        proc.stdout.close()
-        if proc.returncode != 0:
-            raise RuntimeError(
-                "Process returned %d. stdout=%r" % (proc.returncode, stdout)
+    def run_subproc(self, code: str) -> str:
+        try:
+            result = subprocess.run(
+                sys.executable,
+                capture_output=True,
+                input=code,
+                encoding="utf8",
+                check=True,
             )
-        return to_unicode(stdout)
+        except subprocess.CalledProcessError as e:
+            raise RuntimeError(
+                f"Process returned {e.returncode} stdout={e.stdout}"
+            ) from e
+        return result.stdout
 
     def test_single(self):
         # As a sanity check, run the single-process version through this test
index 487622a73c06d08583ec5d051c4005013ca9d20f..d75079bd4a047dbc90669ce610437d8cecf31ad3 100644 (file)
@@ -179,7 +179,10 @@ class AsyncTestCaseWrapperTest(unittest.TestCase):
                 pass
 
         test = Test("test_foo")
-        self.assertIs(inspect.unwrap(test.test_foo), test.test_foo.orig_method)
+        self.assertIs(
+            inspect.unwrap(test.test_foo),
+            test.test_foo.orig_method,  # type: ignore[attr-defined]
+        )
 
 
 class SetUpTearDownTest(unittest.TestCase):
@@ -347,7 +350,7 @@ class GetNewIOLoopTest(AsyncTestCase):
             try:
                 self.orig_loop = asyncio.get_event_loop()
             except RuntimeError:
-                self.orig_loop = None
+                self.orig_loop = None  # type: ignore[assignment]
         self.new_loop = asyncio.new_event_loop()
         asyncio.set_event_loop(self.new_loop)
         super().setUp()
index eb8140d4611ddc49b2edd299684e4d054db53693..1ed6e8585547d71c24f7b3765d3bd24306a3be64 100644 (file)
@@ -649,7 +649,7 @@ def gen_test(  # noqa: F811
         if inspect.iscoroutinefunction(f):
             coro = pre_coroutine
         else:
-            coro = gen.coroutine(pre_coroutine)
+            coro = gen.coroutine(pre_coroutine)  # type: ignore[assignment]
 
         @functools.wraps(coro)
         def post_coroutine(self, *args, **kwargs):
index 55ece9a22b98b77bf3d158d12ca36a818fb21ce2..cf4eba9282479322882bd7ed58fda6a0f480ed82 100644 (file)
@@ -191,7 +191,14 @@ class WSGIContainer(object):
         request_time = 1000.0 * request.request_time()
         assert request.method is not None
         assert request.uri is not None
-        summary = request.method + " " + request.uri + " (" + request.remote_ip + ")"
+        summary = (
+            request.method  # type: ignore[operator]
+            + " "
+            + request.uri
+            + " ("
+            + request.remote_ip
+            + ")"
+        )
         log_method("%d %s %.2fms", status_code, summary, request_time)