Add syntax for declarative record descriptors#233
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
- Coverage 84.29% 0.00% -84.30%
==========================================
Files 35 36 +1
Lines 3756 3945 +189
==========================================
- Hits 3166 0 -3166
- Misses 590 3945 +3355
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Congrats! CodSpeed is installed 🎉
You will start to see performance impacts in the reports once the benchmarks are run from your default branch.
|
6998c7d to
1178dc0
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new declarative syntax for defining flow.record record descriptors by subclassing a RecordBase metaclass-driven base, aiming to preserve backwards compatibility while enabling type-hint-friendly record definitions and optional field docstring extraction.
Changes:
- Add
flow.record.declarative.RecordBase+ metaclass to generateRecordDescriptor/record behavior from annotated subclasses (plusget_field_infofor extracting inline attribute docstrings). - Add extensive tests for declarative records (typing/typenames/defaults/inheritance/init-only vars/docstring extraction) and add a benchmark suite comparing classic vs declarative initialization.
- Update docs and CI/test tooling to accommodate runtime-evaluated annotations and optional benchmark execution.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tox.ini | Adjust test invocation and add a benchmark tox environment. |
| tests/test_benchmark.py | Add benchmark tests comparing classic vs declarative record construction. |
| tests/record/test_declarative.py | Add functional test coverage for declarative record behavior and docstring extraction. |
| tests/conftest.py | Conditionally register/skip the benchmark marker when the plugin isn’t installed. |
| README.md | Document declarative record definitions and usage patterns (InitVar, __post_init__, Ruff note). |
| pyproject.toml | Add Ruff TC configuration for runtime-evaluated base classes and add typing_extensions to a dependency group. |
| flow/record/declarative.py | Introduce the declarative record implementation (RecordBase, field, get_field_info). |
| flow/record/base.py | Factor out _FIELDTYPES_PREFIX and add _default_is_trivial to optimize default handling. |
| .github/workflows/dissect-ci.yml | Enable running benchmarks in CI via the shared workflow template input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This resolves #195.
Disclaimer: this is mostly vibed but with good steering, iteration and a manual check of the code afterwards.
Instead of completely revamping the type system of
flow.record, I opted for it to just be a flavor on top of the existing code. That way it should retain complete backwards compatibility. Then in the future we can decide how much of the original code we would want to change towards this style.Example from the README, showing various options:
Using docstrings also "works" and has a helper to retrieve them.