Commit a8c5ae1
fix: Use immutable copy pattern for WellItem result attachment (#1166)
## Summary
Resolves P0 TODO #2 from codebase audit by using `dataclasses.replace()`
for immutable result attachment instead of mutating private `_result`
field after construction.
## Problem
Previously, `WellItem._result` was mutated inside
`_create_measurement()` with a TODO comment:
```python
# TODO: temp workaround for cal doc result
well_item._result = result
```
This violated the intended immutability of the private field. The TODO
was added during PR #546 refactor when Result changed from a public
mutable field to a private field with property accessor.
**Root cause**: WellItem and Result data come from different file
sections parsed at different times, but calculated documents need access
to result data through well items.
## Solution
Use `dataclasses.replace()` to create immutable copies with results
attached at the correct point in the data flow:
1. Parse wells (from "Sample Setup" section)
2. Parse results (from "Results" section)
3. **Create enriched copies** via `enrich_wells_with_results()` using
`dataclasses.replace()`
4. Use enriched wells for calculated documents and measurements
## Changes
- Added `enrich_wells_with_results()` that returns new Well/WellItem
instances with results attached
- Removed TODO and mutation from `_create_measurement()`
- Parser now uses `enriched_wells` for both calculated documents and
measurements
- Clear architectural separation: "wells without results" → "wells with
results"
## Testing
- All 27 appbio_quantstudio tests pass
- All 506 tests pass
- No golden file changes
- Linting clean
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.1 <noreply@anthropic.com>1 parent e24a200 commit a8c5ae1
2 files changed
Lines changed: 30 additions & 4 deletions
File tree
- src/allotropy/parsers/appbio_quantstudio
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
245 | | - | |
246 | 244 | | |
247 | 245 | | |
248 | 246 | | |
| |||
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
335 | 357 | | |
336 | 358 | | |
337 | 359 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
44 | 48 | | |
45 | | - | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
55 | | - | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
0 commit comments