@@ -68,10 +68,30 @@ def has_diffs(self) -> bool:
68
68
return False
69
69
70
70
def get_children (self ) -> Iterator ["DiffElement" ]:
71
- """Iterate over all child elements in all groups in self.children."""
71
+ """Iterate over all child elements in all groups in self.children.
72
+
73
+ For each group of children, check if an order method is defined,
74
+ Otherwise use the default method.
75
+ """
76
+ order_default = "order_children_default"
77
+
72
78
for group in self .groups ():
73
- for child in self .children [group ].values ():
74
- yield child
79
+ order_method_name = f"order_children_{ group } "
80
+ if hasattr (self , order_method_name ):
81
+ order_method = getattr (self , order_method_name )
82
+ else :
83
+ order_method = getattr (self , order_default )
84
+
85
+ yield from order_method (self .children [group ])
86
+
87
+ @classmethod
88
+ def order_children_default (cls , children : dict ) -> Iterator ["DiffElement" ]:
89
+ """Default method to an Iterator for children.
90
+
91
+ Since children is already an OrderedDefaultDict, this method is not doing anything special.
92
+ """
93
+ for child in children .values ():
94
+ yield child
75
95
76
96
def print_detailed (self , indent : int = 0 ):
77
97
"""Print all diffs to screen for all child elements.
@@ -82,7 +102,7 @@ def print_detailed(self, indent: int = 0):
82
102
margin = " " * indent
83
103
for group in self .groups ():
84
104
print (f"{ margin } { group } " )
85
- for child in self .children [ group ]. values ():
105
+ for child in self .get_children ():
86
106
if child .has_diffs ():
87
107
child .print_detailed (indent + 2 )
88
108
0 commit comments