Skip to content
Snippets Groups Projects
Commit a810b485 authored by Mathieu's avatar Mathieu
Browse files

[dataclasses] (correction) exo 2: use classvar instead of magic number

parent cccefd02
No related branches found
No related tags found
No related merge requests found
......@@ -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__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment