Browse Source

added Person.parents property

Fabian Peter Hammerle 4 years ago
parent
commit
4be0ab930b
1 changed files with 18 additions and 0 deletions
  1. 18 0
      yamily/__init__.py

+ 18 - 0
yamily/__init__.py

@@ -119,6 +119,24 @@ class Person:
             if getattr(person, attr) is not None:
                 setattr(self, attr, getattr(person, attr))
 
+    @property
+    def parents(self) -> typing.Tuple["Person"]:
+        """
+        >>> p = Person("max")
+        >>> p.parents
+        ()
+        >>> p.mother = Person("mum")
+        >>> p.parents
+        (Person(mum),)
+        >>> p.father = Person("dad")
+        >>> p.parents
+        (Person(mum), Person(dad))
+        >>> p.mother = None
+        >>> p.parents
+        (Person(dad),)
+        """
+        return tuple(filter(None, [self.mother, self.father]))
+
 
 class PersonCollection: