Fix several new errors caught by mypy 0.501.

Clear out a bunch of easy to review errors, so we can focus on the more
complicated ones.
This commit is contained in:
Rishi Gupta 2017-03-03 11:30:49 -08:00
parent 024168d85d
commit 28d3af0965
15 changed files with 22 additions and 13 deletions

View File

@ -122,7 +122,7 @@ def main(argv=None):
if not do_send_message(client, message_data):
return 1
return 0
if __name__ == '__main__':
sys.exit(main())

View File

@ -87,7 +87,7 @@ def format_commit_lines(web_url, repo, base, tip):
return "\n".join(summary for summary in commit_summaries)
def send_zulip(email, api_key, site, stream, subject, content):
# type: (str, str, str, str, str, Text) -> str
# type: (str, str, str, str, str, Text) -> None
"""
Send a message to Zulip using the provided credentials, which should be for
a bot in most cases.

View File

@ -86,7 +86,7 @@ def release_deployment_lock():
shutil.rmtree(LOCK_DIR)
def run(args, **kwargs):
# type: (Sequence[str], **Any) -> int
# type: (Sequence[str], **Any) -> None
# Output what we're doing in the `set -x` style
print("+ %s" % (" ".join(args)))

View File

@ -7,7 +7,7 @@ import sys
def check_urls():
# type: () -> bool
# type: () -> None
url_files = ['zproject/urls.py',
'zproject/dev_urls.py',
'zproject/legacy_urls.py',

View File

@ -97,3 +97,4 @@ class BaseDocumentationSpider(scrapy.Spider):
self._set_error_state()
else:
raise Exception(failure.value)
return None

View File

@ -57,6 +57,7 @@ def generic(html_class):
for kw in GENERIC_KEYWORDS:
if kw in html_class:
return True
return False
def display(fns):
# type: (List[str]) -> None

View File

@ -144,13 +144,11 @@ def split_for_id_and_class(element):
def html_branches(text, fn=None):
# type: (str, str) -> List[HtmlTreeBranch]
tree = html_tag_tree(text)
branches = [] # type: List[HtmlTreeBranch]
def walk(node, tag_info_list=None):
# type: (Node, Optional[List[TagInfo]]) -> Node
# type: (Node, Optional[List[TagInfo]]) -> None
info = get_tag_info(node.token)
if tag_info_list is None:
tag_info_list = [info]
@ -195,7 +193,6 @@ def html_tag_tree(text):
def build_id_dict(templates):
# type: (List[str]) -> (Dict[str,List[str]])
template_id_dict = defaultdict(list) # type: (Dict[str,List[str]])
for fn in templates:

View File

@ -241,6 +241,7 @@ class BaseWebsocketHandler(WebSocketHandler):
# close websocket proxy connection if no connection with target websocket server
return self.close()
self.client.write_message(message, binary)
return None
def check_origin(self, origin):
# type: (str) -> bool
@ -262,6 +263,7 @@ class CombineHandler(BaseWebsocketHandler):
# type: (*Any, **Any) -> Optional[Callable]
if self.request.headers.get("Upgrade", "").lower() == 'websocket':
return super(CombineHandler, self).get(*args, **kwargs)
return None
def head(self):
# type: () -> None

View File

@ -402,6 +402,7 @@ class InlineInterestingLinkProcessor(markdown.treeprocessors.Treeprocessor):
if yt_id is not None:
return "https://i.ytimg.com/vi/%s/default.jpg" % (yt_id,)
return None
def twitter_text(self, text, urls, user_mentions, media):
# type: (Text, List[Dict[Text, Text]], List[Dict[Text, Any]], List[Dict[Text, Any]]) -> Element
@ -972,7 +973,7 @@ class UserMentionPattern(markdown.inlinepatterns.Pattern):
el.set('data-user-id', user_id)
el.text = "@%s" % (name,)
return el
return None
class StreamPattern(VerbosePattern):
def find_stream_by_name(self, name):
@ -1001,7 +1002,7 @@ class StreamPattern(VerbosePattern):
stream_name=urllib.parse.quote(force_str(name))))
el.text = u'#{stream_name}'.format(stream_name=name)
return el
return None
class AlertWordsNotificationProcessor(markdown.preprocessors.Preprocessor):
def run(self, lines):

View File

@ -72,6 +72,7 @@ def get_language_name(code):
for lang in get_language_list():
if lang['code'] == code:
return lang['name']
return None
def get_available_language_codes():
# type: () -> List[Text]

View File

@ -194,20 +194,22 @@ def make_client(name):
return client
def find_key_by_email(address):
# type: (Text) -> Text
# type: (Text) -> Optional[Text]
from django.core.mail import outbox
key_regex = re.compile("accounts/do_confirm/([a-f0-9]{40})>")
for message in reversed(outbox):
if address in message.to:
return key_regex.search(message.body).groups()[0]
return None
def find_pattern_in_email(address, pattern):
# type: (Text, Text) -> Text
# type: (Text, Text) -> Optional[Text]
from django.core.mail import outbox
key_regex = re.compile(pattern)
for message in reversed(outbox):
if address in message.to:
return key_regex.search(message.body).group(0)
return None
def message_ids(result):
# type: (Dict[str, Any]) -> Set[int]

View File

@ -41,7 +41,7 @@ class StatsDWrapper(object):
# as our statsd server supports them but supporting
# pystatsd is not released yet
def _our_gauge(self, stat, value, rate=1, delta=False):
# type: (str, float, float, bool) -> str
# type: (str, float, float, bool) -> None
"""Set a gauge value."""
from django_statsd.clients import statsd
if delta:

View File

@ -1354,6 +1354,8 @@ class UserPresence(models.Model):
return 'active'
elif status == UserPresence.IDLE:
return 'idle'
else:
raise ValueError('Unknown status: %s' % (status,))
@staticmethod
def get_status_dict_by_user(user_profile):

View File

@ -470,6 +470,7 @@ class ValidatorTestCase(TestCase):
])('_', val)
if error:
return 'This is not a valid person'
return None
person = {'name': 'King Lear', 'age': 42}
self.assertEqual(check_person(person), None)

View File

@ -278,6 +278,7 @@ class GoogleMobileOauth2Backend(ZulipAuthMixin):
return user_profile
else:
return_data["valid_attestation"] = False
return None
class ZulipRemoteUserBackend(RemoteUserBackend):
create_unknown_user = False