Skip to content

refactor: convert generator methods to with self.indented():#145

Merged
devdanzin merged 1 commit into
mainfrom
generator-indented-conversions-1
Jun 29, 2026
Merged

refactor: convert generator methods to with self.indented():#145
devdanzin merged 1 commit into
mainfrom
generator-indented-conversions-1

Conversation

@devdanzin

Copy link
Copy Markdown
Owner

Continues the generator-complexity refactor groundwork from #144 (tracked under #106). Replaces the manual addLevel(1)/restoreLevel(...) indentation bookkeeping in write_python_code.py with the with 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_functionscompare_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

Net: 259 deletions / 239 insertions, one file.

Verification — all behaviour-preserving

  • Default path: tests/python/test_golden_output.py snapshot unchanged (byte-identical).
  • OOM + deep-dive/thread/async paths (not in the golden snapshot): verified byte-identical with a before/after git stash diff under a pinned PYTHONHASHSEED (set/dict iteration order is otherwise per-process random).
  • Full suite: 328 OK. ruff check + ruff format --check clean.

Left for follow-up

_dispatch_fuzz_on_instance still 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, via self.parent.addLevel) is also still to do.

🤖 Generated with Claude Code

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