From 0d20145b93dbc94729dcde5cdf8f234afaeae55b Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 13 Nov 2019 01:06:02 -0800 Subject: [PATCH] mypy: Upgrade from 0.730 to 0.740. Signed-off-by: Anders Kaseorg --- analytics/views.py | 3 ++- .../files/postgresql/pg_backup_and_purge | 2 +- requirements/dev.txt | 27 ++++++++++--------- requirements/mypy.in | 2 +- requirements/mypy.txt | 27 ++++++++++--------- scripts/lib/zulip_tools.py | 2 +- scripts/setup/flush-memcached | 1 + zerver/lib/outgoing_webhook.py | 2 +- zerver/tests/test_decorators.py | 8 +++--- zerver/tests/test_tornado.py | 6 ++--- zerver/tornado/handlers.py | 2 +- zerver/tornado/websocket_client.py | 2 +- 12 files changed, 46 insertions(+), 38 deletions(-) diff --git a/analytics/views.py b/analytics/views.py index 4e530dfb98..8512fc3111 100644 --- a/analytics/views.py +++ b/analytics/views.py @@ -1122,6 +1122,7 @@ def support(request: HttpRequest) -> HttpResponse: URLValidator()(key_word) parse_result = urllib.parse.urlparse(key_word) hostname = parse_result.hostname + assert hostname is not None if parse_result.port: hostname = "{}:{}".format(hostname, parse_result.port) subdomain = get_subdomain_from_hostname(hostname) @@ -1282,7 +1283,7 @@ def realm_activity_link(realm_str: str) -> mark_safe: def realm_stats_link(realm_str: str) -> mark_safe: url_name = 'analytics.views.stats_for_realm' url = reverse(url_name, kwargs=dict(realm_str=realm_str)) - stats_link = ''.format(url, realm_str) + stats_link = '{}'.format(url, realm_str) return mark_safe(stats_link) def remote_installation_stats_link(server_id: int, hostname: str) -> mark_safe: diff --git a/puppet/zulip/files/postgresql/pg_backup_and_purge b/puppet/zulip/files/postgresql/pg_backup_and_purge index 613c951aa6..583e1266ad 100755 --- a/puppet/zulip/files/postgresql/pg_backup_and_purge +++ b/puppet/zulip/files/postgresql/pg_backup_and_purge @@ -26,7 +26,7 @@ def run(args, dry_run=False): stderr=subprocess.PIPE) stdout, stderr = p.communicate() if p.returncode: - logger.error("Could not invoke %s\nstdout: %s\nstderror: %s" + logger.error("Could not invoke %s\nstdout: %r\nstderror: %r" % (args[0], stdout, stderr)) sys.exit(1) return stdout.decode() diff --git a/requirements/dev.txt b/requirements/dev.txt index a37927c078..a29e69aca9 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -485,18 +485,21 @@ mypy-extensions==0.4.3 \ --hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \ --hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8 \ # via mypy -mypy==0.730 \ - --hash=sha256:1d98fd818ad3128a5408148c9e4a5edce6ed6b58cc314283e631dd5d9216527b \ - --hash=sha256:22ee018e8fc212fe601aba65d3699689dd29a26410ef0d2cc1943de7bec7e3ac \ - --hash=sha256:3a24f80776edc706ec8d05329e854d5b9e464cd332e25cde10c8da2da0a0db6c \ - --hash=sha256:42a78944e80770f21609f504ca6c8173f7768043205b5ac51c9144e057dcf879 \ - --hash=sha256:4b2b20106973548975f0c0b1112eceb4d77ed0cafe0a231a1318f3b3a22fc795 \ - --hash=sha256:591a9625b4d285f3ba69f541c84c0ad9e7bffa7794da3fa0585ef13cf95cb021 \ - --hash=sha256:5b4b70da3d8bae73b908a90bb2c387b977e59d484d22c604a2131f6f4397c1a3 \ - --hash=sha256:84edda1ffeda0941b2ab38ecf49302326df79947fa33d98cdcfbf8ca9cf0bb23 \ - --hash=sha256:b2b83d29babd61b876ae375786960a5374bba0e4aba3c293328ca6ca5dc448dd \ - --hash=sha256:cc4502f84c37223a1a5ab700649b5ab1b5e4d2bf2d426907161f20672a21930b \ - --hash=sha256:e29e24dd6e7f39f200a5bb55dcaa645d38a397dd5a6674f6042ef02df5795046 +mypy==0.740 \ + --hash=sha256:1521c186a3d200c399bd5573c828ea2db1362af7209b2adb1bb8532cea2fb36f \ + --hash=sha256:31a046ab040a84a0fc38bc93694876398e62bc9f35eca8ccbf6418b7297f4c00 \ + --hash=sha256:3b1a411909c84b2ae9b8283b58b48541654b918e8513c20a400bb946aa9111ae \ + --hash=sha256:48c8bc99380575deb39f5d3400ebb6a8a1cb5cc669bbba4d3bb30f904e0a0e7d \ + --hash=sha256:540c9caa57a22d0d5d3c69047cc9dd0094d49782603eb03069821b41f9e970e9 \ + --hash=sha256:672e418425d957e276c291930a3921b4a6413204f53fe7c37cad7bc57b9a3391 \ + --hash=sha256:6ed3b9b3fdc7193ea7aca6f3c20549b377a56f28769783a8f27191903a54170f \ + --hash=sha256:9371290aa2cad5ad133e4cdc43892778efd13293406f7340b9ffe99d5ec7c1d9 \ + --hash=sha256:ace6ac1d0f87d4072f05b5468a084a45b4eda970e4d26704f201e06d47ab2990 \ + --hash=sha256:b428f883d2b3fe1d052c630642cc6afddd07d5cd7873da948644508be3b9d4a7 \ + --hash=sha256:d5bf0e6ec8ba346a2cf35cb55bf4adfddbc6b6576fcc9e10863daa523e418dbb \ + --hash=sha256:d7574e283f83c08501607586b3167728c58e8442947e027d2d4c7dcd6d82f453 \ + --hash=sha256:dc889c84241a857c263a2b1cd1121507db7d5b5f5e87e77147097230f374d10b \ + --hash=sha256:f4748697b349f373002656bf32fede706a0e713d67bfdcf04edf39b1f61d46eb oauthlib==3.1.0 \ --hash=sha256:bee41cc35fcca6e988463cacc3bcb8a96224f470ca547e697b604cc697b2f889 \ --hash=sha256:df884cd6cbe20e32633f1db1072e9356f53638e4361bef4e8b03c9127c9328ea \ diff --git a/requirements/mypy.in b/requirements/mypy.in index 1f26f45368..426161eaad 100644 --- a/requirements/mypy.in +++ b/requirements/mypy.in @@ -2,4 +2,4 @@ # /tools/update-locked-requirements to update requirements/dev.txt # and requirements/mypy.txt. # See requirements/README.md for more detail. -mypy==0.730 +mypy diff --git a/requirements/mypy.txt b/requirements/mypy.txt index 99c8298bf3..48c70b9f61 100644 --- a/requirements/mypy.txt +++ b/requirements/mypy.txt @@ -11,18 +11,21 @@ mypy-extensions==0.4.3 \ --hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \ --hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8 \ # via mypy -mypy==0.730 \ - --hash=sha256:1d98fd818ad3128a5408148c9e4a5edce6ed6b58cc314283e631dd5d9216527b \ - --hash=sha256:22ee018e8fc212fe601aba65d3699689dd29a26410ef0d2cc1943de7bec7e3ac \ - --hash=sha256:3a24f80776edc706ec8d05329e854d5b9e464cd332e25cde10c8da2da0a0db6c \ - --hash=sha256:42a78944e80770f21609f504ca6c8173f7768043205b5ac51c9144e057dcf879 \ - --hash=sha256:4b2b20106973548975f0c0b1112eceb4d77ed0cafe0a231a1318f3b3a22fc795 \ - --hash=sha256:591a9625b4d285f3ba69f541c84c0ad9e7bffa7794da3fa0585ef13cf95cb021 \ - --hash=sha256:5b4b70da3d8bae73b908a90bb2c387b977e59d484d22c604a2131f6f4397c1a3 \ - --hash=sha256:84edda1ffeda0941b2ab38ecf49302326df79947fa33d98cdcfbf8ca9cf0bb23 \ - --hash=sha256:b2b83d29babd61b876ae375786960a5374bba0e4aba3c293328ca6ca5dc448dd \ - --hash=sha256:cc4502f84c37223a1a5ab700649b5ab1b5e4d2bf2d426907161f20672a21930b \ - --hash=sha256:e29e24dd6e7f39f200a5bb55dcaa645d38a397dd5a6674f6042ef02df5795046 +mypy==0.740 \ + --hash=sha256:1521c186a3d200c399bd5573c828ea2db1362af7209b2adb1bb8532cea2fb36f \ + --hash=sha256:31a046ab040a84a0fc38bc93694876398e62bc9f35eca8ccbf6418b7297f4c00 \ + --hash=sha256:3b1a411909c84b2ae9b8283b58b48541654b918e8513c20a400bb946aa9111ae \ + --hash=sha256:48c8bc99380575deb39f5d3400ebb6a8a1cb5cc669bbba4d3bb30f904e0a0e7d \ + --hash=sha256:540c9caa57a22d0d5d3c69047cc9dd0094d49782603eb03069821b41f9e970e9 \ + --hash=sha256:672e418425d957e276c291930a3921b4a6413204f53fe7c37cad7bc57b9a3391 \ + --hash=sha256:6ed3b9b3fdc7193ea7aca6f3c20549b377a56f28769783a8f27191903a54170f \ + --hash=sha256:9371290aa2cad5ad133e4cdc43892778efd13293406f7340b9ffe99d5ec7c1d9 \ + --hash=sha256:ace6ac1d0f87d4072f05b5468a084a45b4eda970e4d26704f201e06d47ab2990 \ + --hash=sha256:b428f883d2b3fe1d052c630642cc6afddd07d5cd7873da948644508be3b9d4a7 \ + --hash=sha256:d5bf0e6ec8ba346a2cf35cb55bf4adfddbc6b6576fcc9e10863daa523e418dbb \ + --hash=sha256:d7574e283f83c08501607586b3167728c58e8442947e027d2d4c7dcd6d82f453 \ + --hash=sha256:dc889c84241a857c263a2b1cd1121507db7d5b5f5e87e77147097230f374d10b \ + --hash=sha256:f4748697b349f373002656bf32fede706a0e713d67bfdcf04edf39b1f61d46eb typed-ast==1.4.0 \ --hash=sha256:1170afa46a3799e18b4c977777ce137bb53c7485379d9706af8a59f2ea1aa161 \ --hash=sha256:18511a0b3e7922276346bcb47e2ef9f38fb90fd31cb9223eed42c85d1312344e \ diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index 103da55aac..0d6539cd38 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -44,7 +44,7 @@ def overwrite_symlink(src, dst): while True: tmp = tempfile.mktemp( prefix='.' + os.path.basename(dst) + '.', - dir=os.path.dirname(dst)) + dir=os.path.dirname(dst)) # type: ignore # https://github.com/python/typeshed/issues/3449 try: os.symlink(src, tmp) except FileExistsError: diff --git a/scripts/setup/flush-memcached b/scripts/setup/flush-memcached index a5b5676845..d7ca91daf3 100755 --- a/scripts/setup/flush-memcached +++ b/scripts/setup/flush-memcached @@ -12,6 +12,7 @@ import scripts.lib.setup_path_on_import from zproject import settings url = urlsplit("//" + settings.MEMCACHED_LOCATION) +assert url.port is not None print("Flushing memcached...") with socket.create_connection((url.hostname, url.port)) as f: diff --git a/zerver/lib/outgoing_webhook.py b/zerver/lib/outgoing_webhook.py index 5ce40ea848..998e5bc3ad 100644 --- a/zerver/lib/outgoing_webhook.py +++ b/zerver/lib/outgoing_webhook.py @@ -212,7 +212,7 @@ def notify_bot_owner(event: Dict[str, Any], notification_message += "\nThe webhook got a response with status code *%s*." % (status_code,) if response_content: notification_message += "\nThe response contains the following payload:\n" \ - "```\n%s\n```" % (response_content,) + "```\n%s\n```" % (str(response_content),) if exception: notification_message += "\nWhen trying to send a request to the webhook service, an exception " \ "of type %s occurred:\n```\n%s\n```" % ( diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 4b32f675c2..73fbc02b65 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -181,8 +181,8 @@ class DecoratorTestCase(TestCase): def test_REQ_converter_and_validator_invalid(self) -> None: with self.assertRaisesRegex(AssertionError, "converter and validator are mutually exclusive"): @has_request_variables - def get_total(request: HttpRequest, # type: ignore # The condition being tested is in fact an error. - numbers: Iterable[int]=REQ(validator=check_list(check_int), + def get_total(request: HttpRequest, + numbers: Iterable[int]=REQ(validator=check_list(check_int), # type: ignore # The condition being tested is in fact an error. converter=lambda x: [])) -> int: return sum(numbers) # nocoverage -- isn't intended to be run @@ -263,8 +263,8 @@ class DecoratorTestCase(TestCase): # Test we properly handle an invalid argument_type. with self.assertRaises(Exception) as cm: @has_request_variables - def test(request: HttpRequest, # type: ignore # The condition being tested is in fact an error. - payload: Any=REQ(argument_type="invalid")) -> None: + def test(request: HttpRequest, + payload: Any=REQ(argument_type="invalid")) -> None: # type: ignore # The condition being tested is in fact an error. # Any is ok; exception should occur in decorator: pass # nocoverage # this function isn't meant to be called test(request) diff --git a/zerver/tests/test_tornado.py b/zerver/tests/test_tornado.py index 8a0e88fcbb..3cd0508bc7 100644 --- a/zerver/tests/test_tornado.py +++ b/zerver/tests/test_tornado.py @@ -181,18 +181,18 @@ class TornadoTestCase(WebSocketBaseTestCase): return view_func(request, user_profile) @staticmethod - def get_cookie_header(cookies: SimpleCookie) -> str: + def get_cookie_header(cookies: "SimpleCookie[str]") -> str: return ';'.join( ["{}={}".format(name, value.value) for name, value in cookies.items()]) - def _get_cookies(self, user_profile: UserProfile) -> SimpleCookie: + def _get_cookies(self, user_profile: UserProfile) -> "SimpleCookie[str]": resp = self.login_with_return(user_profile.email) return resp.cookies @gen.coroutine def _websocket_auth(self, ws: Any, queue_events_data: Dict[str, Dict[str, str]], - cookies: SimpleCookie) -> Generator[str, str, None]: + cookies: "SimpleCookie[str]") -> Generator[str, str, None]: auth_queue_id = ':'.join((queue_events_data['response']['queue_id'], '0')) message = { "req_id": auth_queue_id, diff --git a/zerver/tornado/handlers.py b/zerver/tornado/handlers.py index bd96feb23b..5aa27d3db7 100644 --- a/zerver/tornado/handlers.py +++ b/zerver/tornado/handlers.py @@ -164,7 +164,7 @@ class AsyncDjangoHandlerBase(tornado.web.RequestHandler, base.BaseHandler): # n self.set_header(h[0], h[1]) if not hasattr(self, "_new_cookies"): - self._new_cookies = [] # type: List[http.cookie.SimpleCookie] + self._new_cookies = [] # type: List[http.cookie.SimpleCookie[str]] self._new_cookies.append(response.cookies) self.write(response.content) diff --git a/zerver/tornado/websocket_client.py b/zerver/tornado/websocket_client.py index dcb081f7fa..fa4683f3b8 100644 --- a/zerver/tornado/websocket_client.py +++ b/zerver/tornado/websocket_client.py @@ -60,7 +60,7 @@ class WebsocketClient: @gen.coroutine def _websocket_auth(self, queue_events_data: Dict[str, Dict[str, str]], - cookies: SimpleCookie) -> Generator[str, str, None]: + cookies: "SimpleCookie[str]") -> Generator[str, str, None]: message = { "req_id": self._get_request_id(), "type": "auth",