소스 검색

added Person.parents property

Fabian Peter Hammerle 4 년 전
부모
커밋
4be0ab930b
1개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  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: