refactor: convert generator methods to with self.indented():#145
Merged
Conversation
Continues the generator-complexity refactor groundwork from PR #144 (#106): replace the manual `addLevel(1)`/`restoreLevel(...)` indentation bookkeeping with the `with self.indented():` context manager, so each block's nesting mirrors the generated code's nesting and a level can't leak. Converted in write_python_code.py: - `_write_helper_call_functions` (compare_results + callMethod bodies) - `_fuzz_generic_object_methods` - `_fuzz_methods_on_object_or_specific_types` (skip-trivial block) - `_write_oom_sequence` - `_generate_oom_class_fuzzing` (method-sweep tail) - `_generate_and_write_call` (deep-dive + thread + async blocks) All behaviour-preserving. The golden-output snapshot (tests/python/test_golden_output.py) is unchanged for the default path; the OOM and deep-dive/thread/async paths (not in the golden snapshot) were verified byte-identical with a before/after diff under a pinned PYTHONHASHSEED. Left for follow-up: `_dispatch_fuzz_on_instance` still uses the manual idiom because it embeds the level variable into a generated debug comment and interleaves the h5py writer's side-effecting level return -- a pure conversion would change output. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 29, 2026
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.
Continues the generator-complexity refactor groundwork from #144 (tracked under #106). Replaces the manual
addLevel(1)/restoreLevel(...)indentation bookkeeping inwrite_python_code.pywith thewith self.indented():context manager added in #144, so each emitting block's nesting mirrors the generated code's nesting and a level can't leak.Converted
_write_helper_call_functions—compare_results+callMethodbodies_fuzz_generic_object_methods_fuzz_methods_on_object_or_specific_types— skip-trivial block_write_oom_sequence_generate_oom_class_fuzzing— method-sweep tail_generate_and_write_call— deep-dive + thread + async blocksNet: 259 deletions / 239 insertions, one file.
Verification — all behaviour-preserving
tests/python/test_golden_output.pysnapshot unchanged (byte-identical).git stashdiff under a pinnedPYTHONHASHSEED(set/dict iteration order is otherwise per-process random).ruff check+ruff format --checkclean.Left for follow-up
_dispatch_fuzz_on_instancestill uses the manual idiom: it embeds the level variable into a generated debug comment (# {L_main_if_target_not_none=}) and interleaves the h5py writer's side-effecting level return, so a pure conversion would change output. Cleaning that up (likely dropping the debug-comment cruft) is a separate, behaviour-changing step. The whole h5py writer (write_h5py_code.py, viaself.parent.addLevel) is also still to do.🤖 Generated with Claude Code