-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.py
More file actions
25 lines (22 loc) · 787 Bytes
/
node.py
File metadata and controls
25 lines (22 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from typing import Optional
class Node:
def __init__(
self,
path: Optional[str] = None,
parent: Optional[Node] = None,
obj_name: Optional[str] = None,
):
self.children: list[Node] = []
self.parent: Optional[Node] = parent
self.path: Optional[str] = path
# Graphviz で可視化する際のラベル
self.obj_name: Optional[str] = obj_name
# obj_name をルートノードから順にドットで連結したもの
if parent is None:
self.obj_name_full: Optional[str] = obj_name
else:
self.obj_name_full = (
f"{parent.obj_name_full}.{obj_name}"
if parent.obj_name_full is not None
else obj_name
)