refactor: convert h5py writer to with self.parent.indented():#147
Merged
Conversation
Completes the generator indentation-API migration (#145, #146; under #106) for the last and largest holdout: the h5py code writer. Every manual `addLevel(1)`/`restoreLevel(...)` pair (~150 call sites across all 9 emitting methods) is replaced with the `with self.parent.indented():` context manager, so each block's nesting mirrors the generated code's nesting and a level can't leak. The file now has ZERO manual addLevel/restoreLevel calls. Methods converted: _dispatch_fuzz_on_h5py_instance (preserving its entry-level return contract used by the parent dispatcher), fuzz_one_h5py_class, _write_h5py_file, _write_h5py_dataset_creation_call, _fuzz_one_attributemanager_instance, _fuzz_one_file_instance, _fuzz_one_group_instance, and the large _fuzz_one_dataset_instance. All behaviour-preserving. The h5py writer is not exercised by the golden-output test (it needs numpy+h5py, which the golden harness disables), so this was verified with a dedicated before/after diff harness that drives all 9 methods and snapshots ~1.36 MB of generated code: byte-identical under a pinned PYTHONHASHSEED and a seeded uuid4 (both otherwise per-process random). Full suite 328 OK; ruff check + format clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Completes the generator indentation-API migration (#145, #146; tracked under #106) for the last and largest holdout: the h5py code writer (
fusil/python/h5py/write_h5py_code.py).Every manual
addLevel(1)/restoreLevel(...)pair — ~150 call sites across all 9 emitting methods — is replaced with thewith self.parent.indented():context manager, so each block's nesting mirrors the generated code's nesting and a level can't leak. The file now has zero manualaddLevel/restoreLevelcalls. Net −997/+814 lines (the try/finally + level-variable boilerplate goes away).Methods converted
_dispatch_fuzz_on_h5py_instance(preserving its entry-level return contract that the parent dispatcher relies on),fuzz_one_h5py_class,_write_h5py_file,_write_h5py_dataset_creation_call,_fuzz_one_attributemanager_instance,_fuzz_one_file_instance,_fuzz_one_group_instance, and the large_fuzz_one_dataset_instance(~800 lines).Verification — all behaviour-preserving
The h5py writer is not exercised by the golden-output test (it needs numpy+h5py, which the golden harness disables). So this was verified with a dedicated before/after diff harness that drives all 9 methods and snapshots ~1.36 MB of generated code:
PYTHONHASHSEEDand a seededuuid4(both otherwise per-process random and would mask the comparison).ruff check+ruff format --checkclean.With this merged, the entire Python-fuzzer generator uses the context manager — the only remaining manual idiom anywhere is the single genuine callee-opens-a-level contract between
_dispatch_fuzz_on_instanceand the h5py dispatcher.🤖 Generated with Claude Code