diff --git a/mypy.ini b/mypy.ini index 99d361208f..eb93645605 100644 --- a/mypy.ini +++ b/mypy.ini @@ -40,8 +40,5 @@ strict_optional = True # General exclusions to work on -[mypy-tools.lib.html_branches] -strict_optional = False - [mypy-zthumbor.loaders.helpers] strict_optional = False diff --git a/tools/lib/html_branches.py b/tools/lib/html_branches.py index 0d6b36fd47..3e5eb76075 100644 --- a/tools/lib/html_branches.py +++ b/tools/lib/html_branches.py @@ -53,7 +53,7 @@ class HtmlTreeBranch: 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! self.token = token self.children: List[Node] = [] @@ -133,6 +133,7 @@ def html_branches(text: str, fn: Optional[str] = None) -> List[HtmlTreeBranch]: branches: List[HtmlTreeBranch] = [] def walk(node: Node, tag_info_list: Sequence[TagInfo] = []) -> None: + assert node.token is not None info = get_tag_info(node.token) tag_info_list = [*tag_info_list, info] diff --git a/tools/tests/test_html_branches.py b/tools/tests/test_html_branches.py index 36d268a255..957412f292 100644 --- a/tools/tests/test_html_branches.py +++ b/tools/tests/test_html_branches.py @@ -49,24 +49,31 @@ class TestHtmlBranches(unittest.TestCase): 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.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.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.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.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.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.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.tag, 'p')