Bläddra i källkod

refactor person.merge

Fabian Peter Hammerle 4 år sedan
förälder
incheckning
a84fb9dacf
1 ändrade filer med 9 tillägg och 8 borttagningar
  1. 9 8
      family_tree_yaml/__init__.py

+ 9 - 8
family_tree_yaml/__init__.py

@@ -80,17 +80,18 @@ class Person:
         >>> p2.father = Person("father")
         >>> str(p2)
         'unnamed (*1976-02-01)'
+
+        add attributes of p2 to p1:
         >>> p1.merge(p2)
         >>> str(p1)
         'Max Mustermann (*1976-02-01)'
         >>> p1.mother, p1.father
         (Person(mother), Person(father))
+
+        p2 is unchanged:
+        >>> str(p2)
+        'unnamed (*1976-02-01)'
         """
-        if person.name is not None:
-            self.name = person.name
-        if person.birth_date is not None:
-            self.birth_date = person.birth_date
-        if person.mother is not None:
-            self.mother = person.mother
-        if person.father is not None:
-            self.father = person.father
+        for attr in ["name", "birth_date", "mother", "father"]:
+            if getattr(person, attr) is not None:
+                setattr(self, attr, getattr(person, attr))