Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumPythondataclassesSingle-choice MCQ

A dataclass has a computed attribute declared as field(init=False) and set inside __post_init__. What happens to that computed value when you create a modified copy with dataclasses.replace()?

from dataclasses import dataclass, field, replace @dataclass class Rect: w: int h: int area: int = field(init=False) def __post_init__(self): self.area = self.w * self.h r = Rect(3, 4) r2 = replace(r, w=10) print(r2.area)