|
@@ -25,11 +25,12 @@ class Person:
|
|
|
"""
|
|
|
>>> alice = Person('alice')
|
|
|
>>> alice.name = 'Alice Test'
|
|
|
- >>> alice.birth_date = datetime.date(2019, 12, 23)
|
|
|
+ >>> alice.birth_date = datetime.date(1919, 12, 23)
|
|
|
+ >>> alice.death_date = datetime.date(2019, 11, 1)
|
|
|
>>> alice
|
|
|
- Person(alice, Alice Test, *2019-12-23)
|
|
|
+ Person(alice, Alice Test, *1919-12-23, †2019-11-01)
|
|
|
>>> str(alice)
|
|
|
- 'Alice Test (*2019-12-23)'
|
|
|
+ 'Alice Test (*1919-12-23, †2019-11-01)'
|
|
|
|
|
|
>>> bob = Person('bob')
|
|
|
>>> bob.name = 'Bob Test'
|
|
@@ -40,6 +41,7 @@ class Person:
|
|
|
self.__identifier: str = identifier
|
|
|
self.name: typing.Optional[str] = None
|
|
|
self.birth_date: typing.Optional[datetime.date] = None
|
|
|
+ self.death_date: typing.Optional[datetime.date] = None
|
|
|
self.mother: typing.Optional["Person"] = None
|
|
|
self.father: typing.Optional["Person"] = None
|
|
|
|
|
@@ -61,9 +63,10 @@ class Person:
|
|
|
>>> p.name = "Max Mustermann"
|
|
|
>>> repr(p)
|
|
|
'Person(max-mustermann, Max Mustermann)'
|
|
|
- >>> p.birth_date = datetime.date(1976, 2, 1)
|
|
|
+ >>> p.birth_date = datetime.date(1876, 2, 1)
|
|
|
+ >>> p.death_date = datetime.date(1976, 2, 1)
|
|
|
>>> repr(p)
|
|
|
- 'Person(max-mustermann, Max Mustermann, *1976-02-01)'
|
|
|
+ 'Person(max-mustermann, Max Mustermann, *1876-02-01, †1976-02-01)'
|
|
|
"""
|
|
|
return "{}({})".format(
|
|
|
type(self).__name__,
|
|
@@ -76,6 +79,9 @@ class Person:
|
|
|
"*" + self.birth_date.isoformat()
|
|
|
if self.birth_date is not None
|
|
|
else None,
|
|
|
+ "†" + self.death_date.isoformat()
|
|
|
+ if self.death_date is not None
|
|
|
+ else None,
|
|
|
),
|
|
|
)
|
|
|
),
|
|
@@ -87,12 +93,20 @@ class Person:
|
|
|
>>> p.name = "Max Mustermann"
|
|
|
>>> str(p)
|
|
|
'Max Mustermann'
|
|
|
- >>> p.birth_date = datetime.date(1976, 2, 1)
|
|
|
+ >>> p.birth_date = datetime.date(1876, 2, 1)
|
|
|
+ >>> str(p)
|
|
|
+ 'Max Mustermann (*1876-02-01)'
|
|
|
+ >>> p.death_date = datetime.date(1976, 1, 2)
|
|
|
>>> str(p)
|
|
|
- 'Max Mustermann (*1976-02-01)'
|
|
|
+ 'Max Mustermann (*1876-02-01, †1976-01-02)'
|
|
|
"""
|
|
|
+ attrs = []
|
|
|
+ if self.birth_date is not None:
|
|
|
+ attrs.append("*{}".format(self.birth_date.isoformat()))
|
|
|
+ if self.death_date is not None:
|
|
|
+ attrs.append("†{}".format(self.death_date.isoformat()))
|
|
|
return (self.name or "unnamed") + (
|
|
|
- " (*{})".format(self.birth_date.isoformat()) if self.birth_date else ""
|
|
|
+ " ({})".format(", ".join(attrs)) if attrs else ""
|
|
|
)
|
|
|
|
|
|
def __eq__(self, other: "Person") -> bool:
|
|
@@ -115,24 +129,25 @@ class Person:
|
|
|
>>> str(p1)
|
|
|
'Max Mustermann'
|
|
|
>>> p2 = Person("max2")
|
|
|
- >>> p2.birth_date = datetime.date(1976, 2, 1)
|
|
|
+ >>> p2.birth_date = datetime.date(1876, 2, 1)
|
|
|
+ >>> p2.death_date = datetime.date(1976, 2, 1)
|
|
|
>>> p2.mother = Person("mother")
|
|
|
>>> p2.father = Person("father")
|
|
|
>>> str(p2)
|
|
|
- 'unnamed (*1976-02-01)'
|
|
|
+ 'unnamed (*1876-02-01, †1976-02-01)'
|
|
|
|
|
|
add attributes of p2 to p1:
|
|
|
>>> p1.merge(p2)
|
|
|
>>> str(p1)
|
|
|
- 'Max Mustermann (*1976-02-01)'
|
|
|
+ 'Max Mustermann (*1876-02-01, †1976-02-01)'
|
|
|
>>> p1.mother, p1.father
|
|
|
(Person(mother), Person(father))
|
|
|
|
|
|
p2 is unchanged:
|
|
|
>>> str(p2)
|
|
|
- 'unnamed (*1976-02-01)'
|
|
|
+ 'unnamed (*1876-02-01, †1976-02-01)'
|
|
|
"""
|
|
|
- for attr in ["name", "birth_date", "mother", "father"]:
|
|
|
+ for attr in ["name", "birth_date", "death_date", "mother", "father"]:
|
|
|
if getattr(person, attr) is not None:
|
|
|
setattr(self, attr, getattr(person, attr))
|
|
|
|