mypy: Work around several new mypy bugs in 0.501.

This commit is contained in:
Tim Abbott
2017-03-04 15:18:18 -08:00
parent a3a03bd6a5
commit 75e81253f2
6 changed files with 12 additions and 7 deletions

View File

@@ -6,6 +6,8 @@ secondary Postgres servers' xlog location.
"""
from __future__ import print_function
if False: from mypy_extensions import NoReturn
import subprocess
import re
@@ -17,7 +19,7 @@ states = {
}
def report(state, msg):
# type: (str, str) -> None
# type: (str, str) -> NoReturn
print("%s: %s" % (state, msg))
exit(states[state])

View File

@@ -402,7 +402,7 @@ def authenticated_rest_api_view(is_webhook=False):
if isinstance(profile, UserProfile):
request._email = profile.email
else:
assert isinstance(profile, Deployment)
assert isinstance(profile, Deployment) # type: ignore # https://github.com/python/mypy/issues/2957
request._email = "deployment:" + role
profile.rate_limits = ""
# Apply rate limiting

View File

@@ -205,7 +205,7 @@ def valid_stream(stream_name, token):
return False
def get_message_part_by_type(message, content_type):
# type: (message.Message, Text) -> Text
# type: (message.Message, Text) -> Optional[Text]
charsets = message.get_charsets()
for idx, part in enumerate(message.walk()):
@@ -215,6 +215,7 @@ def get_message_part_by_type(message, content_type):
if charsets[idx]:
text = content.decode(charsets[idx], errors="ignore")
return text
return None
def extract_body(message):
# type: (message.Message) -> Text

View File

@@ -44,7 +44,7 @@ class AddHeaderMixin(object):
super_class = super(AddHeaderMixin, self) # type: ignore # https://github.com/JukkaL/mypy/issues/857
if hasattr(super_class, 'post_process'):
super_ret = super_class.post_process(paths, dry_run, **kwargs)
super_ret = super_class.post_process(paths, dry_run, **kwargs) # type: ignore # https://github.com/python/mypy/issues/2956
else:
super_ret = []
@@ -74,7 +74,7 @@ class RemoveUnminifiedFilesMixin(object):
paths = {k: v for k, v in paths.items() if is_valid(k)}
super_class = super(RemoveUnminifiedFilesMixin, self) # type: ignore # https://github.com/JukkaL/mypy/issues/857
if hasattr(super_class, 'post_process'):
return super_class.post_process(paths, dry_run, **kwargs)
return super_class.post_process(paths, dry_run, **kwargs) # type: ignore # https://github.com/python/mypy/issues/2956
return []

View File

@@ -470,7 +470,7 @@ def setup_event_queue():
load_event_queues()
atexit.register(dump_event_queues)
# Make sure we dump event queues even if we exit via signal
signal.signal(signal.SIGTERM, lambda signum, stack: sys.exit(1))
signal.signal(signal.SIGTERM, lambda signum, stack: sys.exit(1)) # type: ignore # https://github.com/python/mypy/issues/2955
tornado.autoreload.add_reload_hook(dump_event_queues) # type: ignore # TODO: Fix missing tornado.autoreload stub
try:

View File

@@ -2,6 +2,8 @@ from __future__ import absolute_import
import sys
from typing import Any, Dict, List, Optional, Union, Text
if False:
from mypy_extensions import NoReturn
import jinja2
from django.utils import six
@@ -31,7 +33,7 @@ class Jinja2(django_jinja2.Jinja2):
super(Jinja2, self).__init__(params, *args, **kwargs)
def get_template(self, template_name):
# type: (str) -> Template
# type: (str) -> Any # should be Template, see https://github.com/python/mypy/issues/2958
try:
return Template(self.env.get_template(template_name),
self.context_processors,