Dataclasses create __init__ and call __post_init__
- __init__ is implemented and that's how the attributes are initialized
- __post_init__ is called after __init__ to allow for further initializations
examples/oop/dataclasses_init/shapes.py
from dataclasses import dataclass @dataclass class Point(): x : float y : float name : str def __post_init__(self): print(f"In post init: {self.name}")
examples/oop/dataclasses_init/point.py
from shapes import Point p1 = Point(2, 3, 'left')