mirror of https://github.com/zulip/zulip.git
html_branches: Fix strict_optional errors.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
2fb96e94f1
commit
8a03f8a070
3
mypy.ini
3
mypy.ini
|
@ -40,8 +40,5 @@ strict_optional = True
|
||||||
|
|
||||||
# General exclusions to work on
|
# General exclusions to work on
|
||||||
|
|
||||||
[mypy-tools.lib.html_branches]
|
|
||||||
strict_optional = False
|
|
||||||
|
|
||||||
[mypy-zthumbor.loaders.helpers]
|
[mypy-zthumbor.loaders.helpers]
|
||||||
strict_optional = False
|
strict_optional = False
|
||||||
|
|
|
@ -53,7 +53,7 @@ class HtmlTreeBranch:
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, token: Token, parent: "Optional[Node]") -> None:
|
def __init__(self, token: Optional[Token], parent: "Optional[Node]") -> None:
|
||||||
# FIXME parent parameter is not used!
|
# FIXME parent parameter is not used!
|
||||||
self.token = token
|
self.token = token
|
||||||
self.children: List[Node] = []
|
self.children: List[Node] = []
|
||||||
|
@ -133,6 +133,7 @@ def html_branches(text: str, fn: Optional[str] = None) -> List[HtmlTreeBranch]:
|
||||||
branches: List[HtmlTreeBranch] = []
|
branches: List[HtmlTreeBranch] = []
|
||||||
|
|
||||||
def walk(node: Node, tag_info_list: Sequence[TagInfo] = []) -> None:
|
def walk(node: Node, tag_info_list: Sequence[TagInfo] = []) -> None:
|
||||||
|
assert node.token is not None
|
||||||
info = get_tag_info(node.token)
|
info = get_tag_info(node.token)
|
||||||
tag_info_list = [*tag_info_list, info]
|
tag_info_list = [*tag_info_list, info]
|
||||||
|
|
||||||
|
|
|
@ -49,24 +49,31 @@ class TestHtmlBranches(unittest.TestCase):
|
||||||
|
|
||||||
tree = html_tag_tree(html)
|
tree = html_tag_tree(html)
|
||||||
|
|
||||||
|
assert tree.children[0].token is not None
|
||||||
self.assertEqual(tree.children[0].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].token.tag, 'html')
|
self.assertEqual(tree.children[0].token.tag, 'html')
|
||||||
|
|
||||||
|
assert tree.children[0].children[0].token is not None
|
||||||
self.assertEqual(tree.children[0].children[0].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].children[0].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].children[0].token.tag, 'head')
|
self.assertEqual(tree.children[0].children[0].token.tag, 'head')
|
||||||
|
|
||||||
|
assert tree.children[0].children[0].children[0].token is not None
|
||||||
self.assertEqual(tree.children[0].children[0].children[0].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].children[0].children[0].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].children[0].children[0].token.tag, 'title')
|
self.assertEqual(tree.children[0].children[0].children[0].token.tag, 'title')
|
||||||
|
|
||||||
|
assert tree.children[0].children[1].token is not None
|
||||||
self.assertEqual(tree.children[0].children[1].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].children[1].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].children[1].token.tag, 'body')
|
self.assertEqual(tree.children[0].children[1].token.tag, 'body')
|
||||||
|
|
||||||
|
assert tree.children[0].children[1].children[0].token is not None
|
||||||
self.assertEqual(tree.children[0].children[1].children[0].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].children[1].children[0].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].children[1].children[0].token.tag, 'p')
|
self.assertEqual(tree.children[0].children[1].children[0].token.tag, 'p')
|
||||||
|
|
||||||
|
assert tree.children[0].children[1].children[0].children[0].token is not None
|
||||||
self.assertEqual(tree.children[0].children[1].children[0].children[0].token.kind, 'html_singleton')
|
self.assertEqual(tree.children[0].children[1].children[0].children[0].token.kind, 'html_singleton')
|
||||||
self.assertEqual(tree.children[0].children[1].children[0].children[0].token.tag, 'br')
|
self.assertEqual(tree.children[0].children[1].children[0].children[0].token.tag, 'br')
|
||||||
|
|
||||||
|
assert tree.children[0].children[1].children[1].token is not None
|
||||||
self.assertEqual(tree.children[0].children[1].children[1].token.kind, 'html_start')
|
self.assertEqual(tree.children[0].children[1].children[1].token.kind, 'html_start')
|
||||||
self.assertEqual(tree.children[0].children[1].children[1].token.tag, 'p')
|
self.assertEqual(tree.children[0].children[1].children[1].token.tag, 'p')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue