mypy: Convert zerver/lib to use typing.Text.

This commit is contained in:
Robert Hönig
2016-12-21 12:17:53 +00:00
committed by showell
parent 654e8de5ba
commit 0917493588
37 changed files with 290 additions and 307 deletions

View File

@@ -1,7 +1,6 @@
from __future__ import absolute_import
from six import text_type
from typing import Callable, Tuple
from typing import Callable, Tuple, Text
from django.conf import settings
@@ -12,26 +11,26 @@ import logging
# TODO: handle changes in link hrefs
def highlight_with_class(klass, text):
# type: (text_type, text_type) -> text_type
# type: (Text, Text) -> Text
return '<span class="%s">%s</span>' % (klass, text)
def highlight_inserted(text):
# type: (text_type) -> text_type
# type: (Text) -> Text
return highlight_with_class('highlight_text_inserted', text)
def highlight_deleted(text):
# type: (text_type) -> text_type
# type: (Text) -> Text
return highlight_with_class('highlight_text_deleted', text)
def highlight_replaced(text):
# type: (text_type) -> text_type
# type: (Text) -> Text
return highlight_with_class('highlight_text_replaced', text)
def chunkize(text, in_tag):
# type: (text_type, bool) -> Tuple[List[Tuple[text_type, text_type]], bool]
# type: (Text, bool) -> Tuple[List[Tuple[Text, Text]], bool]
start = 0
idx = 0
chunks = [] # type: List[Tuple[text_type, text_type]]
chunks = [] # type: List[Tuple[Text, Text]]
for c in text:
if c == '<':
in_tag = True
@@ -50,7 +49,7 @@ def chunkize(text, in_tag):
return chunks, in_tag
def highlight_chunks(chunks, highlight_func):
# type: (List[Tuple[text_type, text_type]], Callable[[text_type], text_type]) -> text_type
# type: (List[Tuple[Text, Text]], Callable[[Text], Text]) -> Text
retval = u''
for type, text in chunks:
if type == 'text':
@@ -60,7 +59,7 @@ def highlight_chunks(chunks, highlight_func):
return retval
def verify_html(html):
# type: (text_type) -> bool
# type: (Text) -> bool
# TODO: Actually parse the resulting HTML to ensure we don't
# create mal-formed markup. This is unfortunately hard because
# we both want pretty strict parsing and we want to parse html5
@@ -80,7 +79,7 @@ def verify_html(html):
return True
def highlight_html_differences(s1, s2):
# type: (text_type, text_type) -> text_type
# type: (Text, Text) -> Text
differ = diff_match_patch()
ops = differ.diff_main(s1, s2)
differ.diff_cleanupSemantic(ops)