1
1
"""Node.
2
2
"""
3
3
4
- from __future__ import annotations
5
-
6
4
from typing import Any , Dict , List , Optional , Union
7
5
8
6
import numpy as np
@@ -19,9 +17,9 @@ def __init__(
19
17
name : Union [str , int ],
20
18
category : str ,
21
19
value : Optional [np .ndarray ] = None ,
22
- left : Optional [Node ] = None ,
23
- right : Optional [Node ] = None ,
24
- parent : Optional [Node ] = None ,
20
+ left : Optional [" Node" ] = None ,
21
+ right : Optional [" Node" ] = None ,
22
+ parent : Optional [" Node" ] = None ,
25
23
) -> None :
26
24
"""Initialization method.
27
25
@@ -108,39 +106,39 @@ def value(self, value: np.ndarray) -> None:
108
106
self ._value = value
109
107
110
108
@property
111
- def left (self ) -> Node :
109
+ def left (self ) -> " Node" :
112
110
"""Pointer to the node's left child."""
113
111
114
112
return self ._left
115
113
116
114
@left .setter
117
- def left (self , left : Node ) -> None :
115
+ def left (self , left : " Node" ) -> None :
118
116
if left and not isinstance (left , Node ):
119
117
raise e .TypeError ("`left` should be a Node" )
120
118
121
119
self ._left = left
122
120
123
121
@property
124
- def right (self ) -> Node :
122
+ def right (self ) -> " Node" :
125
123
"""Pointer to the node's right child."""
126
124
127
125
return self ._right
128
126
129
127
@right .setter
130
- def right (self , right : Node ) -> None :
128
+ def right (self , right : " Node" ) -> None :
131
129
if right and not isinstance (right , Node ):
132
130
raise e .TypeError ("`right` should be a Node" )
133
131
134
132
self ._right = right
135
133
136
134
@property
137
- def parent (self ) -> Node :
135
+ def parent (self ) -> " Node" :
138
136
"""Pointer to the node's parent."""
139
137
140
138
return self ._parent
141
139
142
140
@parent .setter
143
- def parent (self , parent : Node ) -> None :
141
+ def parent (self , parent : " Node" ) -> None :
144
142
if parent and not isinstance (parent , Node ):
145
143
raise e .TypeError ("`parent` should be a Node" )
146
144
@@ -190,7 +188,7 @@ def position(self) -> np.ndarray:
190
188
return _evaluate (self )
191
189
192
190
@property
193
- def post_order (self ) -> List [Node ]:
191
+ def post_order (self ) -> List [" Node" ]:
194
192
"""Traverses the node in post-order."""
195
193
196
194
# Creates lists for post-order and stacked nodes
@@ -241,7 +239,7 @@ def post_order(self) -> List[Node]:
241
239
return post_order
242
240
243
241
@property
244
- def pre_order (self ) -> List [Node ]:
242
+ def pre_order (self ) -> List [" Node" ]:
245
243
"""Traverses the node in pre-order."""
246
244
247
245
# Creates lists for pre-order and stacked nodes
@@ -267,7 +265,7 @@ def pre_order(self) -> List[Node]:
267
265
268
266
return pre_order
269
267
270
- def find_node (self , position : int ) -> Node :
268
+ def find_node (self , position : int ) -> " Node" :
271
269
"""Finds a node at a given position.
272
270
273
271
Args:
0 commit comments