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

1from __future__ import annotations 

2 

3from typing import TYPE_CHECKING, Optional 

4 

5from .node import Node 

6 

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 

13 

14 

15class Parent(Node): # pylint: disable=too-few-public-methods 

16 """Parent (UnistParent) represents a node in hast containing other nodes (said to be children). 

17 

18 Its content is limited to only other hast content. 

19 """ 

20 

21 def __init__(self, position: Optional[Position] = None, children: Optional[list] = None): 

22 super().__init__(position) 

23 

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 

34 

35 self.children: list[Element | DocType | Comment | Text] = children or []