Skip to content

refactor: convert h5py writer to with self.parent.indented():#147

Merged
devdanzin merged 1 commit into
mainfrom
h5py-writer-indented-conversion
Jun 29, 2026
Merged

refactor: convert h5py writer to with self.parent.indented():#147
devdanzin merged 1 commit into
mainfrom
h5py-writer-indented-conversion

Conversation

@devdanzin

Copy link
Copy Markdown
Owner

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 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. 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:

  • byte-identical before vs. after, under a pinned PYTHONHASHSEED and a seeded uuid4 (both otherwise per-process random and would mask the comparison).
  • Full suite 328 OK; ruff check + ruff format --check clean.

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_instance and the h5py dispatcher.

🤖 Generated with Claude Code

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>
@devdanzin devdanzin merged commit 21d420c into main Jun 29, 2026
2 checks passed
@devdanzin devdanzin deleted the h5py-writer-indented-conversion branch June 29, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant