A robot-log analysis tool may create a revised record by changing a label while expecting every other stored value to remain identical. Python's dataclasses.replace does more than relabel an existing collection of attributes. In a class with constructor-derived fields, creating the replacement can run the calculation again.
An original offline fixture makes that distinction visible using invented sample counts. It does not process a real robot log, configure a device, or establish that a production analysis is correct. The local interpreter reports Python 3.14.7; the official Python reference was labeled 3.14.10 when checked.
Define a derived count explicitly
The fixture defines a mutable dataclass called WindowRecord with three constructor fields: sample_count, trim_each_end, and label. A fourth field, usable_count, is declared with field(init=False). Its value is assigned in __post_init__ using sample_count minus twice trim_each_end.
Construct WindowRecord(12, 2, 'A'). The resulting usable_count is 8, because 12 minus 2 times 2 equals 8. These counts describe an invented arithmetic example. No actual window is trimmed and no claim is made about whether the count is appropriate for a particular signal-processing operation.
The init=False setting excludes usable_count from the generated constructor's parameters. It does not make this mutable instance's attribute read-only. In the fixture, that distinction allows a deliberate diagnostic override before the replacement operation is tested.
Create a visibly inconsistent source object
Assign original.usable_count = 99 after constructing the original record. This intentionally makes the stored derived value inconsistent with the constructor inputs. It is a test condition, not a recommended way to update a valid analysis record or a captured example of a field-service fault.
At this point, the original object's stored values are sample_count=12, trim_each_end=2, label='A', and usable_count=99. Retaining that complete state makes the next comparison informative. Starting with the original value 8 alone would hide whether replacement copied that value or independently recomputed it.
Now evaluate renamed = dataclasses.replace(original, label='B'). The returned object has sample_count=12, trim_each_end=2, label='B', and usable_count=8. The label changed as requested, but the derived value did not remain at the source object's manually overridden 99.
The original object remains label='A' with usable_count=99. The fixture also checks that renamed is a different object. Replacement has created another record; it has not repaired the source object in place or removed evidence of the diagnostic override.
Connect the observation to reconstruction
The official reference says replace constructs the new dataclass object through its __init__ method, allowing __post_init__ to run. It also states that init=False fields are not copied from the source instance. In this fixture, __post_init__ assigns the new count. [Python dataclasses reference](https://docs.python.org/3.14/library/dataclasses.html#dataclasses.replace).
PEP 557 describes the same reconstruction model and discusses why copying init=False fields after initialization was rejected. The fixture illustrates that design with concrete source and result states rather than treating replace as an attribute-for-attribute snapshot operation. [PEP 557](https://peps.python.org/pep-0557/).
A second replacement changes sample_count to 16 while retaining the source object's label and trim_each_end. Its usable_count is 12, matching 16 minus 2 times 2. This control confirms that the declared constructor inputs, rather than the source object's overridden derived count, determine the calculation's result here.
Reject an unsupported derived-field override
The fixture also attempts dataclasses.replace(original, usable_count=99). That request is rejected. A caller cannot supply this init=False field as a replacement constructor field just because the original mutable instance allowed direct assignment to the attribute.
The exception type needs careful reporting. The checked Python 3.14.10 reference and PEP 557 name ValueError for this forbidden override. The installed Python 3.14.7 runtime instead raised TypeError in the executed fixture. The saved evidence records the actual exception class and message; this article does not substitute the documentation's class for the observed result or infer the cause of the difference.
The shared behavioral finding is the rejected request. Code that depends on a particular exception class needs verification on its deployed runtime. Catching one documented class in an untested environment should not be presented as an experimentally verified recovery path.
Initialization inputs may need to be supplied again
A second dataclass, ScaledRecord, has a stored value field, a required scale parameter annotated InitVar[int], and a derived field declared init=False. Its __post_init__ multiplies value by the supplied scale and stores the result in derived.
Constructing ScaledRecord(3, 4) produces value=3 and derived=12. In this deliberately defined class, scale is not assigned to an instance attribute. Inspection of dataclasses.fields returns value and derived, while hasattr(original_scaled, 'scale') is false in the local run.
Trying replace(original_scaled, value=5) fails because the required initialization-only scale was not supplied. The recorded runtime again raises TypeError. Supplying scale=4 produces a replacement with derived=20; supplying scale=5 produces derived=25. The old derived value 12 does not identify which new scale the caller intended.
Preserve the record contract in reports
If an analysis requires reconstruction from declared inputs, the replacement's recomputation may be intentional. If a report instead requires exact preservation of stored evidence, that requirement needs a separately specified representation and handling path. The presence of the word replace in an API name does not settle the report's preservation contract.
Keep constructor inputs, stored derived values, initialization-only dependencies, interpreter version, and expected post-initialization effects available when reviewing the operation. These fixtures demonstrate specific class definitions with deterministic arithmetic. They do not establish behavior for custom constructors, external dependencies, subclasses, or arbitrary application records.
Sources were checked November 18, 2026. All classes, counts, overridden states, comparisons, and exception observations are original offline work. The accompanying AI-generated illustration shows the deliberately inconsistent source record and its reconstructed replacement; it is not an actual robot log or evidence of a corrected production result.