Fix minor things and type hints

This commit is contained in:
Tulir Asokan
2018-09-28 01:02:09 +03:00
parent 828047e272
commit b44d6d2d90
8 changed files with 23 additions and 21 deletions
@@ -148,7 +148,7 @@ def plain_mention_to_text() -> Tuple[List[TypeMessageEntity], Callable[[str], st
return entities, replacer
def init_mx(context: "Context"):
def init_mx(context: "Context") -> None:
global plain_mention_regex, should_bridge_plaintext_highlights
config = context.config
dn_template = config.get("bridge.displayname_template", "{displayname} (Telegram)")
@@ -26,11 +26,11 @@ class MatrixParserCommon:
"ol", "ul", "li",
"h1", "h2", "h3", "h4", "h5", "h6",
"div", "hr", "table") # type: Tuple[str, ...]
list_bullets = ("", "", "", "")
list_bullets = ("", "", "", "") # type: Tuple[str, ...]
@classmethod
def list_bullet(cls, depth: int) -> str:
return cls.list_bullets[(depth - 1) % len(cls.list_bullets)]
return cls.list_bullets[(depth - 1) % len(cls.list_bullets)] + " "
ParsedMessage = Tuple[str, List[TypeMessageEntity]]
@@ -202,7 +202,7 @@ class MatrixParser(HTMLParser, MatrixParserCommon):
else:
prefix = int(math.log(n, 10)) * 3 * " " + 4 * " "
else:
prefix = (f"{self.list_bullet(self._open_tags.count('ul'))} "
prefix = (self.list_bullet(self._open_tags.count('ul'))
if self._list_entry_is_new else 3 * " ")
if not self._list_entry_is_new and not self._line_is_new:
prefix = ""
@@ -80,7 +80,7 @@ class MatrixParser(MatrixParserCommon):
prefix = f"{counter}. "
counter += 1
else:
prefix = f"{cls.list_bullet(ctx.ul_depth)} "
prefix = cls.list_bullet(ctx.ul_depth)
child = child.prepend(prefix)
parts = child.split("\n")
parts = parts[:1] + [part.prepend(indent) for part in parts[1:]]