verysimpletree 1.1__tar.gz → 1.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: verysimpletree
3
- Version: 1.1
3
+ Version: 1.2
4
4
  Summary: lightweight tree data structure for musicxml and musicscore
5
5
  Home-page: https://github.com/alexgorji/verysimpletree.git
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name="verysimpletree"
3
- version="1.1"
3
+ version="1.2"
4
4
  description = "lightweight tree data structure for musicxml and musicscore"
5
5
  authors = ["Alex Gorji <aligorji@hotmail.com>"]
6
6
  license = "MIT"
@@ -43,7 +43,7 @@ class Tree(ABC, Generic[T]):
43
43
 
44
44
  def _raw_traverse(self: T) -> Iterator[T]:
45
45
  yield self
46
- for child in self.get_children():
46
+ for child in self._children:
47
47
  for node in child._raw_traverse():
48
48
  yield node
49
49
 
@@ -76,7 +76,7 @@ class Tree(ABC, Generic[T]):
76
76
  def is_first_child(self) -> bool:
77
77
  if self.is_root:
78
78
  return True
79
- if cast(T, self.up).get_children()[0] == self:
79
+ if cast(T, self.up)._children[0] == self:
80
80
  return True
81
81
  return False
82
82
 
@@ -92,7 +92,7 @@ class Tree(ABC, Generic[T]):
92
92
  """
93
93
  if self.is_root:
94
94
  return True
95
- if cast(T, self.up).get_children()[-1] == self:
95
+ if cast(T, self.up)._children[-1] == self:
96
96
  return True
97
97
  return False
98
98
 
@@ -124,8 +124,8 @@ class Tree(ABC, Generic[T]):
124
124
  :return: next sibling. ``None`` if this is the last current child of the parent.
125
125
  :rtype: :obj:`~tree.tree.Tree`
126
126
  """
127
- if self.up and self != self.up.get_children()[-1]:
128
- return cast(T, self.up.get_children()[self.up.get_children().index(self) + 1])
127
+ if self.up and self != self.up._children[-1]:
128
+ return cast(T, self.up._children[self.up._children.index(self) + 1])
129
129
  else:
130
130
  return None
131
131
 
@@ -137,8 +137,8 @@ class Tree(ABC, Generic[T]):
137
137
  :return: previous sibling. ``None`` if this is the first child of the parent.
138
138
  :rtype: :obj:`~tree.tree.Tree`
139
139
  """
140
- if self.up and self != self.up.get_children()[0]:
141
- return cast(T, self.up.get_children()[self.up.get_children().index(self) - 1])
140
+ if self.up and self != self.up._children[0]:
141
+ return cast(T, self.up._children[self.up._children.index(self) - 1])
142
142
  else:
143
143
  return None
144
144
 
@@ -200,7 +200,7 @@ class Tree(ABC, Generic[T]):
200
200
  :return: list of added children of type.d
201
201
  :rtype: list[:obj:`~tree.tree.Tree`]
202
202
  """
203
- return [cast(T, ch) for ch in self.get_children() if isinstance(ch, type_)]
203
+ return [cast(T, ch) for ch in self._children if isinstance(ch, type_)]
204
204
 
205
205
  def get_distance(self, reference: Optional[T] = None) -> int:
206
206
  """
@@ -250,14 +250,14 @@ class Tree(ABC, Generic[T]):
250
250
  if level == 0:
251
251
  output = [self]
252
252
  elif level == 1:
253
- output = self.get_children()
253
+ output = self._children
254
254
  else:
255
255
  output = []
256
256
  for child in self.get_layer(level - 1):
257
257
  if child.is_leaf:
258
258
  output.append(child)
259
259
  else:
260
- output.extend(child.get_children())
260
+ output.extend(child._children)
261
261
 
262
262
  if key is None:
263
263
  return output
@@ -279,7 +279,7 @@ class Tree(ABC, Generic[T]):
279
279
  """
280
280
  output: list[Union[Any, list[Any]]] = []
281
281
  child: T
282
- for child in self.get_children():
282
+ for child in self._children:
283
283
  if not child.is_leaf:
284
284
  output.append(child.get_leaves(key=key))
285
285
  else:
@@ -350,9 +350,9 @@ class Tree(ABC, Generic[T]):
350
350
  if parent is None:
351
351
  return '0'
352
352
  elif self.get_level() == 1:
353
- return str(parent.get_children().index(self) + 1)
353
+ return str(parent._children.index(self) + 1)
354
354
  else:
355
- return f"{parent.get_position_in_tree()}.{parent.get_children().index(self) + 1}"
355
+ return f"{parent.get_position_in_tree()}.{parent._children.index(self) + 1}"
356
356
 
357
357
  def get_reversed_path_to_root(self) -> list[T]:
358
358
  """
@@ -426,7 +426,7 @@ class Tree(ABC, Generic[T]):
426
426
 
427
427
  def get_list_representation(self, key: Callable[["Tree[T]"], Any]) -> list[list[Any]]:
428
428
  result: list[list[Any]] = [key(self)]
429
- for child in self.get_children():
429
+ for child in self._children:
430
430
  result.append(child.get_list_representation(key=key))
431
431
  return result
432
432
 
@@ -476,10 +476,10 @@ class Tree(ABC, Generic[T]):
476
476
  :param child:
477
477
  :return: None
478
478
  """
479
- if child not in self.get_children():
479
+ if child not in self._children:
480
480
  raise ChildNotFoundError
481
481
  child._parent = None
482
- self.get_children().remove(child)
482
+ self._children.remove(child)
483
483
  self._reset_iterators()
484
484
 
485
485
  def remove_children(self) -> None:
@@ -490,7 +490,7 @@ class Tree(ABC, Generic[T]):
490
490
 
491
491
  :return: None
492
492
  """
493
- for child in self.get_children()[:]:
493
+ for child in self._children[:]:
494
494
  parent = child.get_parent()
495
495
  if parent is not None:
496
496
  parent.remove(child)
@@ -505,16 +505,16 @@ class Tree(ABC, Generic[T]):
505
505
  :return: None
506
506
  """
507
507
  if hasattr(old, '__call__'):
508
- list_of_olds = [ch for ch in self.get_children() if old(ch)]
508
+ list_of_olds = [ch for ch in self._children if old(ch)]
509
509
  else:
510
- list_of_olds = [ch for ch in self.get_children() if ch == old]
510
+ list_of_olds = [ch for ch in self._children if ch == old]
511
511
  if not list_of_olds:
512
512
  raise ValueError(f"{old} not in list.")
513
513
  self._check_child_to_be_added(new)
514
- old_index = self.get_children().index(list_of_olds[index])
515
- old_child = self.get_children()[old_index]
516
- self.get_children().remove(old_child)
517
- self.get_children().insert(old_index, new)
514
+ old_index = self._children.index(list_of_olds[index])
515
+ old_child = self._children[old_index]
516
+ self._children.remove(old_child)
517
+ self._children.insert(old_index, new)
518
518
  old_child._parent = None
519
519
  self._reset_iterators()
520
520
  new._parent = self
File without changes