Repository navigation
Share writer checks and remove model mixins - #897
Conversation
tompollard
left a comment
There was a problem hiding this comment.
Removing the mixins is the milestone #866 was aiming for. The consolidation keeps every write output unchanged, but it changes two public Record methods when n_sig is unset. Both are small fixes. The focused header, .dat, fixture, parity and warning tests pass (418 passed, 44 expected skips), as do the offline suite (2,295 passed, 48 skipped) and Ruff.
What I checked, against main (69fbc95)
-
_WriteModelno longer inherits anything. Its MRO is_WriteModel, object. -
The modern writers are unchanged. I compared bytes and errors across versions:
- every readable sample header through
write_recordandSignalRead.write; - 3,000 random sparse records;
- 15 invalid header fields;
- 480 flattened multi-segment writes across all four writers;
- my 1,464-write
SignalRead.writemutation check.
Every outcome is identical.
- every readable sample header through
-
The public
Recordwriters are unchanged. SinceRecord._write_checked_headernow goes through the shared function, I also compared:rdrecord(..., m2s=True).wrsamp()on every sample header, both kinds and both layouts;rdheader(...).wrheader()on every sample header;wrheader()andwrsamp()on 3,000 malformedRecords: list fields that are short, long or tuples,n_sigoff by one or unset, mixed file names and offsets, out-of-range samples, and missingsig_len.
All outcomes match
main, including errors, files left behind, anything printed, and the record's state afterwards. -
Performance is unchanged. All five writer and kind combinations on
100skeware within noise ofmain, with identical peak memory.
To fix: direct check_sig_cohesion and check_field_cohesion calls with n_sig=None
On the same 3,000 malformed records, I also called the two public cohesion methods directly. All 596 differences come from records whose n_sig is unset:
-
check_sig_cohesion(298 calls).mainraised the existingValueError, such assig_len and n_sig do not match shape of d_signalorn_sig does not match the length of e_d_signal, or aTypeError. Now every one raisesAttributeError: 'NoneType' object has no attribute 'n_channels'._check_dat_valuestreatsn_sig=Noneas "not given" and falls back tosignal_snapshot.n_channels, but a directRecordcall passes no snapshot. In 61 expanded calls,mainhad also filledsamps_per_framein place before raising, and that no longer happens.A minimal fix is to fall back only when there is a snapshot:
if n_sig is None and signal_snapshot is not None:. ThenNonereaches the same comparisons as before and raises the same errors. -
check_field_cohesion(298 calls). Onmain,if n_channels > 0raisedTypeError: '>' not supported between instances of 'NoneType' and 'int'. Nowif self.n_sig == 0: returnletsNonethrough to the length check, which raisesValueError: The length of field: fmt must match field n_sig.(or, in 6 calls, a differentTypeError). Keeping the old> 0guard restores the previous behaviour.
These only affect direct calls on incomplete records, and the new check_field_cohesion message is arguably clearer. But this PR is meant to be behaviour-neutral, and the AttributeError is a worse message than before. Please restore both, and add a test that calls each method on a Record without n_sig, so the behaviour stays as intended.
|
Good catch. I fixed both cases in fe22e5d. I added tests for uniform and expanded signal checks and the header check. All three pass on pre-change main and on this branch. The focused writer and parity tests pass (413 passed, 44 expected skips), as does the full offline suite (2,298 passed, 48 skipped). |
Summary
Consolidate the duplicate header and signal validation left by #895 and #896.
Record._write_checked_headernow calls the explicit header function, its snapshot cohesion check calls the shared helper, andSignalMixin.check_sig_cohesionuses the explicit shape and range checker while keeping its direct-call checksum and initial-value checks._WriteModelno longer inheritsBaseRecord,HeaderMixin, orSignalMixin.This is the first #866 cleanup step. The
_legacy_*paths and parity test remain independent for this review. Removing them needs a separate checklist that maps each parity case to a fixed byte fixture or test. The model still projects channel fields to lists while preparing a write; that remaining metadata representation work is separate from inheritance removal.Checks
.dattests, and warning caller tests passed (417 passed, 44 expected skips in the focused run).Record.check_sig_cohesioncalls matched pre-change main in 2,000 generated cases, including errors, printed diagnostics, and in-place samples-per-frame defaults.git diff --checkpassed.No changelog entry because this changes only internal writer structure.