22
33import copy
44import heapq
5- from typing import (
6- Any ,
7- Generator ,
8- Iterable ,
9- List ,
10- Mapping ,
11- Optional ,
12- Set ,
13- Tuple ,
14- TypeVar ,
15- )
5+ from typing import Any , Generator , Iterable , Mapping , TypeVar
166
177from bigtree .globals import ASSERTIONS
188from bigtree .utils import exceptions , iterators
@@ -126,7 +116,7 @@ class BaseNode:
126116 3. ``set_attrs(attrs: dict)``: Set node attribute name(s) and value(s)
127117 4. ``go_to(node: Self)``: Get a path from own node to another node from same tree
128118 5. ``append(node: Self)``: Add child to node
129- 6. ``extend(nodes: List [Self])``: Add multiple children to node
119+ 6. ``extend(nodes: list [Self])``: Add multiple children to node
130120 7. ``copy()``: Deep copy self
131121 8. ``sort()``: Sort child nodes
132122 9. ``plot()``: Plot tree in line form
@@ -138,12 +128,12 @@ class BaseNode:
138128
139129 def __init__ (
140130 self ,
141- parent : Optional [ T ] = None ,
142- children : Optional [ List [ T ]] = None ,
131+ parent : T | None = None ,
132+ children : list [ T ] | None = None ,
143133 ** kwargs : Any ,
144134 ):
145- self .__parent : Optional [ T ] = None
146- self .__children : List [T ] = []
135+ self .__parent : T | None = None
136+ self .__children : list [T ] = []
147137 if children is None :
148138 children = []
149139 self .parent = parent
@@ -187,7 +177,7 @@ def __check_parent_loop(self, new_parent: T) -> None:
187177 )
188178
189179 @property
190- def parent (self : T ) -> Optional [ T ] :
180+ def parent (self : T ) -> T | None :
191181 """Get parent node.
192182
193183 Returns:
@@ -330,7 +320,7 @@ def __check_children_loop(self: T, new_children: Iterable[T]) -> None:
330320 seen_children .append (id (new_child ))
331321
332322 @property
333- def children (self : T ) -> Tuple [T , ...]:
323+ def children (self : T ) -> tuple [T , ...]:
334324 """Get child nodes.
335325
336326 Returns:
@@ -339,7 +329,7 @@ def children(self: T) -> Tuple[T, ...]:
339329 return tuple (self .__children )
340330
341331 @children .setter
342- def children (self : T , new_children : List [T ] | Tuple [T ] | Set [T ]) -> None :
332+ def children (self : T , new_children : list [T ] | tuple [T ] | set [T ]) -> None :
343333 """Set child nodes.
344334
345335 Args:
@@ -457,7 +447,7 @@ def siblings(self: T) -> Iterable[T]:
457447 return tuple (child for child in self .parent .children if child is not self )
458448
459449 @property
460- def left_sibling (self : T ) -> Optional [ T ] :
450+ def left_sibling (self : T ) -> T | None :
461451 """Get sibling left of self.
462452
463453 Returns:
@@ -470,7 +460,7 @@ def left_sibling(self: T) -> Optional[T]:
470460 return self .parent .children [child_idx - 1 ]
471461
472462 @property
473- def right_sibling (self : T ) -> Optional [ T ] :
463+ def right_sibling (self : T ) -> T | None :
474464 """Get sibling right of self.
475465
476466 Returns:
@@ -594,7 +584,7 @@ def from_dict(cls, input_dict: Mapping[str, Any]) -> BaseNode:
594584
595585 def describe (
596586 self , exclude_attributes : Iterable [str ] = (), exclude_prefix : str = ""
597- ) -> List [ Tuple [str , Any ]]:
587+ ) -> list [ tuple [str , Any ]]:
598588 """Get node information sorted by attribute name, returns list of tuples.
599589
600590 Examples:
@@ -679,7 +669,7 @@ def append(self: T, other: T) -> T:
679669 other .parent = self
680670 return self
681671
682- def extend (self : T , others : List [T ]) -> T :
672+ def extend (self : T , others : list [T ]) -> T :
683673 """Add others as children of self. Can be chained.
684674
685675 Args:
@@ -743,7 +733,7 @@ def plot(self, *args: Any, **kwargs: Any) -> plt.Figure:
743733 reingold_tilford (self )
744734 return plot_tree (self , * args , ** kwargs )
745735
746- def query (self , query : str , debug : bool = False ) -> List [T ]:
736+ def query (self , query : str , debug : bool = False ) -> list [T ]:
747737 """Query tree using Tree Definition Language.
748738
749739 Examples:
0 commit comments