diff --git a/d_dataclasses/02_person.py b/d_dataclasses/02_person.py index 24dde68160767b928a8a7c236573136eefbbc6f0..122a6c864273a626b53865a4a3cd36d2103f6290 100644 --- a/d_dataclasses/02_person.py +++ b/d_dataclasses/02_person.py @@ -5,7 +5,8 @@ We want the Person dataclass to have 3 attribute: the name, last name, and age o But we want to be able to give the birthday (we limit ourselves to the year), and the class should determine the age on its own. """ import doctest -from dataclasses import dataclass, InitVar +from dataclasses import InitVar, dataclass +from typing import ClassVar @dataclass @@ -26,10 +27,11 @@ class Person: age: int = None birthday: InitVar[int] = None + YEAR: ClassVar[int] = 2019 def __post_init__(self, birthday: int): if self.age is None and birthday is not None: - self.age = 2019 - birthday + self.age = self.YEAR - birthday if __name__ == '__main__':