|
@@ -280,6 +280,34 @@ class PersonCollection:
|
|
|
coparents.add(coparent)
|
|
|
return coparents
|
|
|
|
|
|
+ def get_coparents_recursively(
|
|
|
+ self, parent: typing.Union[Person, str]
|
|
|
+ ) -> typing.Set[Person]:
|
|
|
+ """
|
|
|
+ >>> c = PersonCollection()
|
|
|
+ >>> child_a = Person("child-a")
|
|
|
+ >>> child_a.father = Person("father")
|
|
|
+ >>> child_a.mother = Person("mother-a")
|
|
|
+ >>> c.add_person(child_a)
|
|
|
+ Person(child-a)
|
|
|
+ >>> child_b = Person("child-b")
|
|
|
+ >>> child_b.father = Person("father")
|
|
|
+ >>> child_b.mother = Person("mother-b")
|
|
|
+ >>> c.add_person(child_b)
|
|
|
+ Person(child-b)
|
|
|
+ >>> sorted(c.get_coparents_recursively("mother-a"), key=lambda p: p.identifier)
|
|
|
+ [Person(father), Person(mother-a), Person(mother-b)]
|
|
|
+ >>> c.get_coparents_recursively("child-a")
|
|
|
+ set()
|
|
|
+ """
|
|
|
+ coparents = self.get_coparents(parent)
|
|
|
+ last_len = None
|
|
|
+ while len(coparents) != last_len:
|
|
|
+ for coparent in set(coparents):
|
|
|
+ coparents.update(self.get_coparents(coparent))
|
|
|
+ last_len = len(coparents)
|
|
|
+ return coparents
|
|
|
+
|
|
|
def __iter__(self) -> "PersonCollection":
|
|
|
"""
|
|
|
>>> c = PersonCollection()
|