Coverage for phml\nodes\parent.py: 100%
11 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -0600
« prev ^ index » next coverage.py v6.5.0, created at 2022-12-08 16:33 -0600
1from __future__ import annotations
3from typing import TYPE_CHECKING, Optional
5from .node import Node
7if TYPE_CHECKING:
8 from .comment import Comment
9 from .doctype import DocType
10 from .element import Element
11 from .position import Position
12 from .text import Text
15class Parent(Node): # pylint: disable=too-few-public-methods
16 """Parent (UnistParent) represents a node in hast containing other nodes (said to be children).
18 Its content is limited to only other hast content.
19 """
21 def __init__(self, position: Optional[Position] = None, children: Optional[list] = None):
22 super().__init__(position)
24 if children is not None:
25 for child in children:
26 if hasattr(child, "type") and child.type in [
27 "element",
28 "text",
29 "doctype",
30 "root",
31 "comment",
32 ]:
33 child.parent = self
35 self.children: list[Element | DocType | Comment | Text] = children or []