|
@@ -235,6 +235,36 @@ class PersonCollection:
|
|
|
return self.__children[parent]
|
|
|
return self.get_children(parent.identifier)
|
|
|
|
|
|
+ def get_coparents(
|
|
|
+ self, parent: typing.Union[Person, str]
|
|
|
+ ) -> typing.Iterator[Person]:
|
|
|
+ """
|
|
|
+ >>> c = PersonCollection()
|
|
|
+
|
|
|
+ >>> alice = Person('alice')
|
|
|
+ >>> alice.father = Person('bob')
|
|
|
+ >>> c.add_person(alice)
|
|
|
+ Person(alice)
|
|
|
+ >>> list(c.get_coparents('bob'))
|
|
|
+ []
|
|
|
+
|
|
|
+ >>> alice.mother = Person('carol')
|
|
|
+ >>> c.add_person(alice)
|
|
|
+ Person(alice)
|
|
|
+ >>> list(c.get_coparents('bob'))
|
|
|
+ [Person(carol)]
|
|
|
+ >>> list(c.get_coparents(c['carol']))
|
|
|
+ [Person(bob)]
|
|
|
+ """
|
|
|
+ if isinstance(parent, Person):
|
|
|
+ for coparent in self.get_coparents(parent.identifier):
|
|
|
+ yield coparent
|
|
|
+ return
|
|
|
+ for child in self.get_children(parent):
|
|
|
+ for coparent in child.parents:
|
|
|
+ if coparent.identifier != parent:
|
|
|
+ yield coparent
|
|
|
+
|
|
|
def __iter__(self) -> "PersonCollection":
|
|
|
"""
|
|
|
>>> c = PersonCollection()
|